On 11/08/2021 19:10, MRAB wrote:
On 2021-08-11 18:10, Wolfram Hinderer via Python-list wrote:
Am 11.08.2021 um 05:22 schrieb Terry Reedy:
Python is a little looser about whitespace than one might expect
from reading 'normal' code when the result is unambiguous in that it
cannot really mean anything other than what it does. Two other
examples:
>>> if3: print('yes!')
yes!
>>> [0] [0]
0
Not sure what you mean here - is it a joke? The first looks like an if
statement, but isn't. The missing space *does* make a difference. (Try
"if0" instead.)
I see what you mean. It's a type annotation:
var: type
where the "type" is a print statement!
The second is normal indexing, which allows white space. I wouldn't
consider that surprising, but maybe I should? (Honest question, I really
don't know.)
I looked at the if3 example, and I was gobsmacked. I momentarily
assumed that "if3" was parsed as "if 3", although that clearly makes no
sense ("if3" is a valid identifier).
Then I saw the "if0" example and I was even more gobsmacked, because it
showed that my assumption was wrong.
I've never used type annotations, I've never planned to used them. And
now that all is revealed, I'm afraid that my reaction is: I'm even more
inclined never to use them, because these examples are (to me) so confusing.
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list