+ 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)

29th Sep 2023, 12:43 PM
David Landenberger
David Landenberger - avatar
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.
29th Sep 2023, 1:06 PM
Dragon RB
Dragon RB - avatar
+ 6
David Landenberger You could see my detailed aswer in Q&A here: https://sololearn.com/discuss/3242402/?ref=app
29th Sep 2023, 2:44 PM
JaScript
JaScript - avatar
+ 3
Dragon RB JaScript Thanks for the help. I appreciate you!
29th Sep 2023, 3:11 PM
David Landenberger
David Landenberger - avatar
0
What do you want to make?
29th Sep 2023, 12:47 PM
D1M3
D1M3 - avatar