I guess the quickest way is to show you my interaction:
>>> a = 3
>>> b = a
>>> a is b
True
>>> a = 4
>>> print (b)
3
a) What I thought: by assigning b = a, I've created an alias for a. Basically, b is another reference to the same object that a refers to.
b) I confirmed that (?) by asking if 'a is b' and received True, meaning they are both the same object
c) Then I refute my own conjecture by changing a and querying b, seeing that they are not the same object, as the object referred to by 'a' has been modified, but the object referred to by 'b' remains unmodified...
Now I am confused.
Sorry for newbie question, I really tried googling this first!
My current explanation is that I am being confused with another programming language, where everything is an object, as opposed to python, where integers are not objects and therefore a = b does not create an alias.
(for example: with lists instead of integers, the interaction with python console shows aliasing working like the book says)
However, in that case, why did 'a is b' return True?
>>> a = 3
>>> b = a
>>> a is b
True
>>> a = 4
>>> print (b)
3
a) What I thought: by assigning b = a, I've created an alias for a. Basically, b is another reference to the same object that a refers to.
b) I confirmed that (?) by asking if 'a is b' and received True, meaning they are both the same object
c) Then I refute my own conjecture by changing a and querying b, seeing that they are not the same object, as the object referred to by 'a' has been modified, but the object referred to by 'b' remains unmodified...
Now I am confused.
Sorry for newbie question, I really tried googling this first!
My current explanation is that I am being confused with another programming language, where everything is an object, as opposed to python, where integers are not objects and therefore a = b does not create an alias.
(for example: with lists instead of integers, the interaction with python console shows aliasing working like the book says)
However, in that case, why did 'a is b' return True?