+ 2
Could anyone please help me defining what does "is" do??
i was typing this in the compiler and it returned as follows : >>>1 is int False >>>"s" is str False . Why is that?! Shouldn't it print True instead??
2 ответов
+ 8
"==" just checks for logical equality
"is" checks for two arguments referring to the same memory address (ergo to the same object)
1 == 1.0, but 1 points to an integer object, while 1.0 to a float, so 1 is not 1.0
a = [1, 2, 3] # one list object
b = [1, 2, 3] # another list object
c = a
a == b, but a is not b
a == c and (or *because*) a is c
+ 1
If you want to test a condition use '=='
>>>1 == int
True
>>> "s" == str
True