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! While you're at it, check out some resources Treehouse students have shared here.

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

Python Python Collections (2016, retired 2019) Lists Shopping List Take Three

Aditya Pandey
Aditya Pandey
7,210 Points

What does 'is' do?

I don't understand what the 'is' keyword is used for. Can anyone clarify?

1 Answer

Hi Aditya,

the "is" keyword compares one value to another and tells you whether the statement is true or not. so for example you can run the code below and both print statements return "True"

a = 1
b = 1
print(a is b)
print(a == b)

Try it out in workspaces.

Best of luck!

Leeland Miller
Leeland Miller
1,324 Points

You have to be careful with using is though. is tests for identity, not equality. What that means is it is looking to see if the two values are in the same place in memory.

For example

list_one = [1, 2, 3]
list_two = [1, 2, 3]

print(list_one == list_two) # Prints True
print(list_one is list_two) # Prints False