Andrew Koenig: > The observation is that if an object is immutable, there's > no legitimate reason to know whether it's distinct from > another object with the same type and value. There is an idiom (I've seen it more in Lisp than in python) of creating a fresh object to act as a sentinel. "done with this data" might well appear in the input, but the specific newly-created-string (which happens to look just like that) can't appear. The sentinal is usually a mutable object, but it is sometimes a string indicating the object's meaning. ("fail") It is surprising that some objects (like small integers) cannot be used, but I don't think the answer is to make the entire idiom unusable. You could argue that they ought to be using (id(x) == id(y)) to emphasize that == isn't enough, but ... (x is y) seems just as clear, and the reference manual (5.9) says that is tests for object identity. -jJ
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4