Why Is Assignment Not Allowed In If Statement In Python
Why is assignment not allowed in if statements in Python ? In other languages like c it is possible to use this code. code Python: >>> if x=12: SyntaxError: invalid synta
Solution 1:
It's true. For better and worse, Python distinguishes strictly between expressions and statements, and the latter don't have values. In particular, assignment statements don't have values, and so can't be used in conditionals.
Solution 2:
Remember for Python to use two equals signs.
if x == 12
*Enter expressions here*
Post a Comment for "Why Is Assignment Not Allowed In If Statement In Python"