Welcome to the Treehouse Community
Looking to learn something new?
Use of "is" in python
Here is the code-
a="Done" b="Done" c=input("Enter Done :") #c takes the value "Done" print(a is b) print(a is c)
The first print statement prints True, whereas the second one prints False. Why is that happening?
Steven Parker216,136 Points
The is operator is an identity test, unlike == which is an equality test. Your string literal referenced by both variables a and b (because Python optimized them to one object) is stored separately from the input string referenced by c. That's why "a is b" but not "a is c".
However, if you tried "a == c" you would find that to be True.