Confused About when to use a single = sign vs ==


Basically what the title says. Sometimes the program works when i use a single equal sign. Sometimes it works when i use 2 equal signs. Anybody mind explaining the case of each?



Their distinction is actually quite simple: one is for assignment, the other for comparison.

a = "assigned value"       # the string is assigned to a

b == "comparison operand"  # the string is compared to b

An assignment is a statement, so yields only the new reference. A comparison is an expression and always yields a Boolean, True or False.