News for hackers. Stuff that matters.
Re:WTF Python: Exploring and understanding Python through su... by Doxin on Thursday February 11, 2021 @03:50AM (#26099561)
And it'd be unfair to that new language too. Basically all of the WTFs in the OP are things you don't run into, unless you're writing deeply deeply weird code, at which point it's hardly the languages fault that it does weird things.
Re:WTF Python: Exploring and understanding Python through su... by sorokod on Thursday February 11, 2021 @05:15AM (#26099988)
Not a python dev, but what is deeply weird about the examples in "Strings can be tricky..." section?
Re:WTF Python: Exploring and understanding Python through su... by olau on Thursday February 11, 2021 @06:14AM (#26100319)
Both "id()" and its companion "is" are almost never used in practice - I don't think the tutorial mentions them. At least when it comes to id(), you'd have to find that in the reference where it will explain how it works.

If you're familiar with C, id() returns the memory address of the thing given to it, and "x is y" is like "id(x) == id(y)". So "x" is "x" is asking whether the Python runtime happened to put the two strings in the same place in memory, not whether the two strings are equal.

("is" is commonly used for one thing - testing against None. So you might write "a is None". I think that's just because someone once got bitten by a badly overloaded == operator. Just like some people will write === in all their Javascript, in case an incorrect type sneaks in.)