easy question on parsing python: "is not None"
tjreedy at udel.edu
Fri Aug 13 07:12:10 CEST 2010
On 8/12/2010 10:52 PM, Matt Schinckel wrote:
>>>> a = "hello"
>>>> b = "hello"
>>>> a is b
> Ooh, that looks dangerous.
Only for mutable objects
> Are they the same object?
>>>> a += "o"
This is equivalent to a = a+"o". The expression creates a new object.
The assignment binds the object to name 'a'.
> (Python does not make two copies of small strings until it needs to).
Python never copies *any* object until you ask it to. It never made a
copy of the original 'a' here either. It combined the values of two
string objects to make a new string object with a new value.
Terry Jan Reedy
More information about the Python-list