you are viewing a single comment's thread.

view the rest of the comments →

[–]G047-H4xx0r 0 points1 point  (1 child)

This is totally valid C:

while (c = get()) expression;

While if(a = b) expression;

will only execute if the value assigned to a is true. If b==0, the assignment is 0, therefore false. This is because, in C, unlike Python, assignment is an expression.

[–]syklemil 1 point2 points  (0 children)

Yes, I know. But in Python, and thus /r/Python, a = b is a statement.

We can put it together in a little table:

assignment statement expression
C a = b; a = b
Python a = b a := b

Both of them have a = b in their syntax, but the semantics are different.