3 ms·
I've seen these before and every single time, it's mostly based on a misunderstanding of certain language features that only a beginner coder would do (for exam
by Sohcahtoa82 4y ago
I've seen these before and every single time, it's mostly based on a misunderstanding of certain language features that only a beginner coder would do (for example, not knowing that Python does not do block-level variable scoping, so loop variables leak) or an abuse of an implementation detail (for example, integers under 255 being singletons).
"is" is not the same as "==". Confusing the two is a rookie mistake, yet is treated like a "gotcha".
- eslaught 4y ago> not knowing that Python does not do block-level variable scoping, so loop variables leak For what it's worth, it took me a long time to internalize this (more than ten years after first learning Python), I think partly because the way most people teach Python is to say what scopes Python has instead of saying what scopes it doesn't have. While it's bad style to abuse this, I would definitely consider this a part of Python that a lot of working developers probably don't understand well.
- d0mine 4y agoYes. Scopes are complicated e.g., class Foo: a = [1,2,3] b = [4,5,6] c = [x * y for x in a for y in b] that leads to NameError: name 'b' is not defined https://bugs.python.org/issue3692 https://bugs.python.org/issue3692
- deleted 4y ago[deleted]