4 ms·
I'm amazed at how long I've been working in python and never known that assignment works in this way. I suppose I just avoid parts of the language that I don't
by anitil 5y ago
I'm amazed at how long I've been working in python and never known that assignment works in this way. I suppose I just avoid parts of the language that I don't understand.
Looking through the archives, it's a really interesting blog in general
- londons_explore 5y agoIt's fallout of the fact that assignment must be a statement, and cannot be an expression. Eg. This is wrong in python, while it would be allowed in c-like languages print(a=5)
- orf 5y agoIt’s possible now with the walrus operator though: print(a:=5)
- klyrs 5y agoI mean, it generally looks like a terrible idea, so absent of malice to the reader (or code golf shenanigans) nobody would do this. Not a surprise that the behavior is surprising...
- heavyset_go 5y agoSome languages wear the things that make you go WTF on their sleeves. In contrast, Python's surprises pop up slowly over time, and in places where you'd least expect them.
- SOLAR_FIELDS 5y agoI wonder if it’s because of their subtlety. I assume you are referencing JavaScript, where the warts are impossible to ignore because you can’t write an everyday program as a beginner without running into them. This sort of thing from the article is just not something I would typically be trying to do in the normal course of shuffling data around.