News for hackers. Stuff that matters.
Re:What the Fuck Python by andy_ppp on Saturday July 19, 2025 @04:42PM (#44619190)
I think honestly it is you who misread my comment... I was saying the id() issue isn't a real problem, the weirdness around "wtf!" not being equal to itself under some circumstances is very confusing. Seems Google Colab isn't loading here.
Re:What the Fuck Python by Jtsummers on Saturday July 19, 2025 @05:38PM (#44619665)
`is` is more like doing this in C:

  char* s1 = "wtf!";
  char* s2 = "wtf!";
  if (s1 == s2) { ... }
They may or may not be stored in the same place depending on your compiler (clang and gcc yes, msvc no, at least with just a quick default build). If you actually want to do an equality check, you need to use `==` (in Python) which would be like using `strcmp` in C.

> "wtf!" not being equal to itself

It is equal to itself, but multiple variables referencing that string may not hold references to the same (literal, in memory) string.

Re:What the Fuck Python by ziml77 on Saturday July 19, 2025 @05:00PM (#44619349)
But "is" doesn't check equality. It checks reference equality. Maybe the real wtf here is they made that check a temptingly short infix operator rather than a function named reference_equals().
Re:What the Fuck Python by zahlman on Saturday July 19, 2025 @05:25PM (#44619567)
"wtf!" is consistently equal to itself in Python.

The fact that you could have separate string objects both representing that text, is entirely orthogonal to that.