+ 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??
14 ответов
+ 4
No. Its all about the memory address. If it's the same address, they are the same. If not, then they arent
+ 3
It is related to memory locations . I meant it will check if the memory location is same as checked or not
+ 2
ravilnicki Excellent 👌 man! you're info is really helpful
+ 1
Slick But why they was assigned the same address if if they value
+ 1
ravilnicki so if they have the same id, so if one of theme change its value the other will also
+ 1
ravilnicki Thx for clarifying, I get it now
Thank u a lot ☺️
+ 1
Saad Khan I don't think so, it is all about 'pointers'
Read the comment of ravilnicki above
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
- 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.