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

28th Jan 2018, 12:49 PM
Ahmed Kamal
Ahmed Kamal - avatar
2 odpowiedzi
+ 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
28th Jan 2018, 1:03 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
If you want to test a condition use '==' >>>1 == int True >>> "s" == str True
28th Jan 2018, 1:00 PM
Sebastian Keßler
Sebastian Keßler - avatar