+ 1
== Vs is in Python
What will the output of the following code be? (Treat the comma in the multiple choice answer as a newline.) a = [1, 2, 3] b = a c = [1, 2, 3] print(a == b) print(a is b) print(a == c) print(a is c) .
3 Answers
+ 7
a = [1, 2, 3]
b = a
c = [1, 2, 3]
print(a == b)
print(a is b)
print(a == c)
print(a is c)
print("a", a, id(a))
print("b", b, id(b))
print("c", c, id(c))
+ 4
I have mentioned it in this with an example.
Refer point 6.
https://www.sololearn.com/discuss/1187881/?ref=app
+ 3
True #b is referring to a. So have same content
True #b is referring to a. So b is just internal copy of a
True #both a and c have same content
False #a and c are not same. Only their content are same. In python, we call they have different signatures