On 8/7/20 11:55 AM, Marco Sulla wrote: > Commonly, in imperative languages like C, you can write > > if (a = b) {...} > > This is allowed in C, even if a = b is not an expression, but an > assignment statement. 99% of times you simply wrong and wanted:
But in C (and related languages) it IS an expression, and C doesn't have an 'assignment statement' but an 'expression statement', which is the source of the issue. = is just another operator, which happens to modify the value of its left operand. Python makes assignment a full top level type of statement, so = can't be misused in an expression thinking it means an equality test (and then added recently the := operator, so that for the cases you actually want to do assignments in the middle of an expression you can). -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list