How "is" is work in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How "is" is work in python?

I'm tryin to understand how "is" does work, so I code this lines and examine the results? -If I assign two variables "a, b" the same values, I get (a is b )----> True -If I change their values I get False So I conclude with: -If a and b having the same value so they point at same object "based on the function of "is" as I read on the net', and vice versa My question is: am I right in my conclusion??

30th Jan 2022, 9:42 AM
Ahmed
Ahmed - avatar
9 Answers
+ 4
No. Its all about the memory address. If it's the same address, they are the same. If not, then they arent
30th Jan 2022, 9:59 AM
Slick
Slick - avatar
+ 3
It is related to memory locations . I meant it will check if the memory location is same as checked or not
31st Jan 2022, 4:48 PM
Yusra
+ 2
ravilnicki Excellent 👌 man! you're info is really helpful
31st Jan 2022, 10:24 AM
Saad Khan
Saad Khan - avatar
+ 1
Slick But why they was assigned the same address if if they value
30th Jan 2022, 10:08 AM
Ahmed
Ahmed - avatar
+ 1
ravilnicki so if they have the same id, so if one of theme change its value the other will also
30th Jan 2022, 10:33 AM
Ahmed
Ahmed - avatar
+ 1
ravilnicki Thx for clarifying, I get it now Thank u a lot ☺️
30th Jan 2022, 12:53 PM
Ahmed
Ahmed - avatar
+ 1
Saad Khan I don't think so, it is all about 'pointers' Read the comment of ravilnicki above
31st Jan 2022, 8:24 AM
Ahmed
Ahmed - avatar
0
“is” operator can be used to efficiently check for the equality of two string objects. The is operator returns True if the two variables point to the same data object, Else, returns False "==" operator compares the string in a character-by-character manner and returns True if the two strings are equal, otherwise, it returns False
31st Jan 2022, 10:24 PM
Henok Tewolde
- 1
Your question is really Hilarious, but let me tell you something, like you say ' something is equal to that thing' in the same way 'is' works in python. It is always preferred to use operators like !,= etc.
31st Jan 2022, 2:28 AM
Saad Khan
Saad Khan - avatar