I really like the idea of ββnulling - but it has an unexpected side effect:
>>> print divmod(5, 3) (1, 2) >>> x, null = divmod(5, 3) >>> print null 2
For those who work primarily in Python, this is probably not a problem: the null value should be as significant as _.
However, if you switch between other languages ββsuch as Javascript, it is entirely possible to accidentally write a comparison with a null value instead of None. Instead of spitting out the usual error when comparing with an unknown variable, Python just silently accepts it, and now you get true and false conditions that you do not fully expect ... this is such an error when you look at the code for an hour and do not can understand that wth is untrue until he suddenly hits you and you feel like an idiot.
The obvious fix does not work:
>>> x, None = divmod(5, 3) File "<stdin>", line 1 SyntaxError: cannot assign to None
... which is really disappointing. Python (and any other language on the planet) allows you to exclude all parameters, regardless of the number of returned variables:
>>> divmod(5, 3)
... but explicitly discarding parameters by setting them to None is not allowed?
It seems that the stupidity of the Python interpreter characterizes the purpose of None as a syntax error, and not an intentional choice with a clear result. Can anyone think of a rationale for this?
David stein
source share