Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have the following code:
a = [] b = a
when I compile the following code I get this:
print(b is a) --> True print(b is []) --> False
if b = a then shouldn't b is [] return True?
b is []
True
is
[]
try that:
a = [] b = a print(id(a)) print(id(b)) print(id([]))
And you will see that a and b refers to the same object, while next [] is a different one. Check if b to see if b is not empty list
if b
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
ismeans referential equality, so that both things refer to the same object, two separate lists are not the same object.iswith literals.[]are the same object.[]is just an empty list, which can be constructed in many ways.