+ 1
please explain
Can someone please explain why (c is d) in the following code is false? a = b = [1] c, d = [1], [1] print(a is b) print(c is d) print(c) print(d)
4 Answers
+ 3
In Python, `is` checks if 2 objects refer to the same object. It returns True if 2 objects belongs to same object, otherwise False, even though they share the same value.
Example:
n = 0
x = n
print(x is n) #True
n, x = 0
print(x is n) #False
For checking equality, please use `==`, which returns True if 2 objects have the same value, False otherwise.
+ 6
David Landenberger You could see my detailed aswer in Q&A here:
https://sololearn.com/discuss/3242402/?ref=app
+ 3
Dragon RB JaScript Thanks for the help. I appreciate you!
0
What do you want to make?