Source From Here
Question
I've got a python program where two variables are set to the value 'public'. In a conditional expression I have the comparison var1 is var2 which fails, but if I change it to var1 == var2 it returns True. now if I open my python interpreter and do the same "is" comparison it succeeds:
How-To
is is identity testing, == is equality testing. what happens in your code would be emulated in the interpreter like this:
Supplement
* Is there a difference between `==` and `is` in Python?
Question
I've got a python program where two variables are set to the value 'public'. In a conditional expression I have the comparison var1 is var2 which fails, but if I change it to var1 == var2 it returns True. now if I open my python interpreter and do the same "is" comparison it succeeds:
How-To
is is identity testing, == is equality testing. what happens in your code would be emulated in the interpreter like this:
Supplement
* Is there a difference between `==` and `is` in Python?
沒有留言:
張貼留言