Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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 Parker227,127 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.