I declared two variables as follows (one of which is the reverse of the other):
a = "test"
b = "tset" # reverse of a
I then ran this into the interpretor which returned the below value:
'test' # value returned
As you can see, it reversed the string which made it exactly like the first variable
However, when I execute this statement, the results are not quite the same:
a is b[::-1]
False # returns false after executing above statement
a is "test", so is b[::-1]. So why is it that the condition does not evaluate to
To check for "values" equality you should use the operator
>>> a == b[::-1] True
So why is it that the condition does not evaluate to True?
is keyword is used to compare objects identity; in other words, if the objects are the same.