AssignCompares
Observed in Published Research

AssignCompares
Incorrect

= compares two values

Correct

= assigns a value to a variable

Correction
Here is what's right.

In Python, and in many other languages, the = operator does not compare values, but it assigns the value on its right to the variable on its left.

Thus, a = 1 will store a reference to the value 1 in the variable a.

This also means that 1 = 2 will cause a syntax error, because the left-hand-side of the assignment (1) does not represent a variable, which means that it’s not possible to store a value in it. The interpreter will report an error when it encounters expressions like 1 = 2.

Origin
Where could this misconception come from?

This misconception may stem from prior knowledge in mathematics, where = means equals (i.e., is a comparison operator).

Symptoms
How do you know your students might have this misconception?

Students may use (inadvertently or not) a single = operator in expressions used as conditions.

The most common place where the mistake happens is probably within if statements, such as:

if x = 1:
    ...

Value
How can you build on this misconception?

In other programming languages (such as Pascal), the = operator indeed performs a comparison between its operands. In those languages, a different operator (e.g, := ) is used for an assignment.

Language

Python

Concepts

Expressible In

Other Languages

Literature References

The following papers directly or indirectly provide qualitative or quantitative evidence related to this misconception.

altadmri37MillionCompilations2015

Repository mining study (BlueJ Blackbox)

250000+ students across the world

Java
Artifact

Mistakes studied:
A: Confusing the assignment operator with the comparison operator
45082 / 250000
Users making mistake
brownNoviceJavaProgrammingMistakes2017

Quantitative systematic research analyzing 100+ M compilation events and surveying educators perceptions about 18 selected mistakes

900+ students and 76 educators

Java

Errors studied:
(A)eqSyn: Confusing the assignment operator (=) with the equality operator (==)
405748 / 100000000
Compilation events containing this error
chiodiniSurveyingUpperSecondaryTeachers2025

Quantitative systematic research

97 Swiss high school teachers and their students

Python
Artifact

Programming Language Misconceptions studied:
AC: AssignCompares
3 / 97
Teachers hold misconception
85 / 97
Teachers familiar with misconception
Important: 71
Somewhat Important: 19
Not So Important: 5
Not Important: 1
I'm not sure: 1
Importance (reported by teachers)
Frequently: 30
Multiple Times: 38
At Least Once: 14
Never: 10
I don't know: 5
Prevalence in students (reported by teachers)
hristovaIdentifyingCorrectingJava2003

Qualitative (survey of instructors and students)

Unknown number of undergraduate students, professors, SIGCSE members

Java

Errors studied:
Syntax1: Confusing the assignment operator with the comparison operator
mccallANewLookatNoviceProgrammingErrors

Quantitative systematic research analyzing 1000+ randomly-selected compilation events

199 user sessions (each sessions associated with a different user)

Java
Artifact

Errors studied:
Tab8.33: '=' used in place of '=='
6 / 1000
Compilation events containing this error
qianTeachersPerceptionsStudent2020

A quantitative survey of teachers to assess their perceptions of the frequency and importance of student misconceptions

44 high school teachers

Python

Misconceptions studied:
AppendixA.19(F): The symbol '=' tests for equality
Never
1
 
2.93
Very Frequent
4
Average Perceived Frequency
AppendixA.19(I): The symbol '=' tests for equality
Not Important
1
 
3.4
Very Important
4
Average Importance Rating
rodrigoAnAnalysisOfJavaProgramming2013

Qualitative and quantitative study analyzing about 190'000 compilation logs

180 undergraduates

Java

Errors studied:
Fig11: Code snippet showing a use of '=' as comparator
maInvestigatingImprovingModelOfProgramming2011

Quantitative and qualitative analysis of incorrect mental models related to variable assignment using open-ended testing

60 novice students

Java

Mental model studied:
ME: Viewing '=' as a comparison operator
6 / 60
Students showing this (incorrect) mental model