Yep, 'in' is a operator used to check if a value is exists in a sequence or not. Answer from meesid on reddit.com
🌐
W3Schools
w3schools.com › python › ref_keyword_is.asp
Python is Keyword
Python Examples Python Compiler ... Bootcamp Python Certificate Python Training ... The is keyword is used to test if two variables refer to the same object....
Discussions

How is the 'is' keyword implemented in Python? - Stack Overflow
... the is keyword that can be used for equality in strings. >>> s = 'str' >>> s is 'str' True >>> s is 'st' False I tried both __is__() and __eq__() but they didn't wor... More on stackoverflow.com
🌐 stackoverflow.com
python - Is there a difference between "==" and "is"? - Stack Overflow
My Google-fu has failed me. In Python, are the following two tests for equality equivalent? n = 5 # Test one. if n == 5: print 'Yay!' # Test two. if n is 5: print 'Yay!' Does this hold t... More on stackoverflow.com
🌐 stackoverflow.com
python - Understanding the "is" operator - Stack Overflow
In fact, the compiler can go even further: 'ab' + 'c' can be converted to 'abc' by the optimizer, in which case it can be folded together with an 'abc' constant in the same module. Again, this is something Python is allowed but not required to do. But in this case, CPython always folds small ... More on stackoverflow.com
🌐 stackoverflow.com
Why you should almost never use “is” in Python
I think this post should be titled "You should know what 'is' and '==' do before using them". If you don't know what they do, obviously you wouldn't know how to use them correctly, so should you learn. And if you do know what they do, then there aren't any hidden gotchas (as far as I know) where you'd think one of them is the right choice but the other actually is. More on reddit.com
🌐 r/Python
145
138
June 16, 2015
🌐
GeeksforGeeks
geeksforgeeks.org › python › check-if-element-exists-in-list-in-python
Check if element exists in list in Python - GeeksforGeeks
Python provides an 'in' statement that checks if an element is present in an iterable or not.
Published   November 13, 2025
🌐
Real Python
realpython.com › ref › keywords › is
is | Python Keywords – Real Python
In Python, the is keyword lets you test for object identity. Unlike the equality operator ==, which checks if the values of two objects are the same, is checks whether two variables point to the same object in memory.
🌐
Real Python
realpython.com › python-in-operator
Python's "in" and "not in" Operators: Check for Membership – Real Python
January 26, 2025 - They have entirely different meanings. The in operator checks if a value is in a collection of values, while the in keyword in a for loop indicates the iterable that you want to draw from.
🌐
GeeksforGeeks
geeksforgeeks.org › python › is-keyword-in-python
is keyword in Python - GeeksforGeeks
July 12, 2025 - In Python, keywords are case-sensitive. The "is" keyword in Python is used to test object identity. The “is keyword” is used to test whether two variables belong to the same object.
Find elsewhere
🌐
BrainStation®
brainstation.io › learn › python › is-keyword
Python Is Keyword (2026 Tutorial & Examples) | BrainStation®
February 4, 2025 - The is keyword in Python will compare whether two values refer to the same object or not. It is different from the equality operator in Python because…
🌐
Codedamn
codedamn.com › news › python
Understanding 'is in' Operator in Python
July 3, 2023 - It returns True if the value is ... useful when working with data structures in Python, and it's a quick and efficient way to check for the existence of a value....
🌐
Mimo
mimo.org › glossary › python › in-operator
Master Python's in Operator for Various Coding Scenarios
A search engine might use the in operator to check if a keyword is present in a search query. ... search_query = "best Python tutorials" keyword = "Python" if keyword in search_query: print("Keyword found") # Outputs: Keyword found else: print("Keyword not found")
🌐
Reuven Lerner
lerner.co.il › home › blog › python › why you should almost never use “is” in python
Why you should almost never use "is" in Python — Reuven Lerner
August 6, 2021 - In such a case, it’s pretty clear that x and y are both pointing to precisely the same object. They aren’t just equal in value; they are one and the same — aliases for one another. We can ask Python if this is true by using the “is” operator, also known as the “identity operator.” “is” doesn’t compare the values of x and y.
🌐
W3Schools
w3schools.com › python › python_operators.asp
Python Operators
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Operators are used to perform operations on variables and values. In the example below, we use the + operator to add together two values: ... Although the + operator is often used to add together two values, like in the example above, it can also be used to add together a variable and a value, or two variables:
🌐
Quora
quora.com › Is-the-equivalence-of-is-in-Python
Is '===' the equivalence of 'is' in Python? - Quora
So, the “is” operator compares the value of the pointer, not the value it points to. “===,” on the other hand, compares the values of two variables. ... Some particularly observant people have caught something that I missed when I was ...
Top answer
1 of 13
1211

is will return True if two variables point to the same object (in memory), == if the objects referred to by the variables are equal.

>>> a = [1, 2, 3]
>>> b = a
>>> b is a 
True
>>> b == a
True

# Make a new copy of list `a` via the slice operator, 
# and assign it to variable `b`
>>> b = a[:] 
>>> b is a
False
>>> b == a
True

In your case, the second test works only because Python caches small integer objects, which is an implementation detail. For larger integers, this does not work:

>>> 1000 is 10**3
False
>>> 1000 == 10**3
True

The same holds true for string literals:

>>> "a" is "a"
True
>>> "aa" is "a" * 2
True
>>> x = "a"
>>> "aa" is x * 2
False
>>> "aa" is intern(x*2)
True

Please see this question as well.

2 of 13
425

There is a simple rule of thumb to tell you when to use == or is.

  • == is for value equality. Use it when you would like to know if two objects have the same value.
  • is is for reference equality. Use it when you would like to know if two references refer to the same object.

In general, when you are comparing something to a simple type, you are usually checking for value equality, so you should use ==. For example, the intention of your example is probably to check whether x has a value equal to 2 (==), not whether x is literally referring to the same object as 2.


Something else to note: because of the way the CPython reference implementation works, you'll get unexpected and inconsistent results if you mistakenly use is to compare for reference equality on integers:

>>> a = 500
>>> b = 500
>>> a == b
True
>>> a is b
False

That's pretty much what we expected: a and b have the same value, but are distinct entities. But what about this?

>>> c = 200
>>> d = 200
>>> c == d
True
>>> c is d
True

This is inconsistent with the earlier result. What's going on here? It turns out the reference implementation of Python caches integer objects in the range -5..256 as singleton instances for performance reasons. Here's an example demonstrating this:

>>> for i in range(250, 260): a = i; print "%i: %s" % (i, a is int(str(i)));
... 
250: True
251: True
252: True
253: True
254: True
255: True
256: True
257: False
258: False
259: False

This is another obvious reason not to use is: the behavior is left up to implementations when you're erroneously using it for value equality.

Top answer
1 of 11
211

You misunderstood what the is operator tests. It tests if two variables point the same object, not if two variables have the same value.

From the documentation for the is operator:

The operators is and is not test for object identity: x is y is true if and only if x and y are the same object.

Use the == operator instead:

print(x == y)

This prints True. x and y are two separate lists:

x[0] = 4
print(y)  # prints [1, 2, 3]
print(x == y)   # prints False

If you use the id() function you'll see that x and y have different identifiers:

>>> id(x)
4401064560
>>> id(y)
4401098192

but if you were to assign y to x then both point to the same object:

>>> x = y
>>> id(x)
4401064560
>>> id(y)
4401064560
>>> x is y
True

and is shows both are the same object, it returns True.

Remember that in Python, names are just labels referencing values; you can have multiple names point to the same object. is tells you if two names point to one and the same object. == tells you if two names refer to objects that have the same value.

2 of 11
75

Another duplicate was asking why two equal strings are generally not identical, which isn't really answered here:

>>> x = 'a' 
>>> x += 'bc'
>>> y = 'abc'
>>> x == y
True
>>> x is y
False

So, why aren't they the same string? Especially given this:

>>> z = 'abc'
>>> w = 'abc'
>>> z is w
True

Let's put off the second part for a bit. How could the first one be true?

The interpreter would have to have an "interning table", a table mapping string values to string objects, so every time you try to create a new string with the contents 'abc', you get back the same object. Wikipedia has a more detailed discussion on how interning works.

And Python has a string interning table; you can manually intern strings with the sys.intern method.

In fact, Python is allowed to automatically intern any immutable types, but not required to do so. Different implementations will intern different values.

CPython (the implementation you're using if you don't know which implementation you're using) auto-interns small integers and some special singletons like False, but not strings (or large integers, or small tuples, or anything else). You can see this pretty easily:

>>> a = 0
>>> a += 1
>>> b = 1
>>> a is b
True
>>> a = False
>>> a = not a
>>> b = True
a is b
True
>>> a = 1000
>>> a += 1
>>> b = 1001
>>> a is b
False

OK, but why were z and w identical?

That's not the interpreter automatically interning, that's the compiler folding values.

If the same compile-time string appears twice in the same module (what exactly this means is hard to define—it's not the same thing as a string literal, because r'abc', 'abc', and 'a' 'b' 'c' are all different literals but the same string—but easy to understand intuitively), the compiler will only create one instance of the string, with two references.

In fact, the compiler can go even further: 'ab' + 'c' can be converted to 'abc' by the optimizer, in which case it can be folded together with an 'abc' constant in the same module.

Again, this is something Python is allowed but not required to do. But in this case, CPython always folds small strings (and also, e.g., small tuples). (Although the interactive interpreter's statement-by-statement compiler doesn't run the same optimization as the module-at-a-time compiler, so you won't see exactly the same results interactively.)


So, what should you do about this as a programmer?

Well… nothing. You almost never have any reason to care if two immutable values are identical. If you want to know when you can use a is b instead of a == b, you're asking the wrong question. Just always use a == b except in two cases:

  • For more readable comparisons to the singleton values like x is None.
  • For mutable values, when you need to know whether mutating x will affect the y.
🌐
Reddit
reddit.com › r/python › why you should almost never use “is” in python
r/Python on Reddit: Why you should almost never use “is” in Python
June 16, 2015 - The is operator compares the identities of the two referenced objects, which, in CPython, actually are identical—but this only holds for certain integer values, because CPython maintains a global pool of commonly-used integer objects to share ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-between-and-is-operator-in-python
Difference between == and is operator in Python - GeeksforGeeks
September 18, 2025 - Let’s break it down with examples. It is used when you want to check whether two objects contain same data (value), regardless of whether they are stored in same memory location.
🌐
dbader.org
dbader.org › blog › difference-between-is-and-equals-in-python
The Difference Between “is” and “==” in Python – dbader.org
December 28, 2016 - Python has two operators for equality comparisons, “is” and “==” (equals). In this article I’m going to teach you the difference between the two and when to use each with a few simple examples.
🌐
Replit
replit.com › home › discover › how to use 'is' in python
How to use 'is' in Python | Replit
1 month ago - Just like None, the boolean values True and False are singletons, meaning there's only one instance of each. That's why using the is operator for identity checks like x is True is the standard, reliable approach. It confirms you're working with the actual boolean object. This singleton pattern doesn't apply to mutable objects like lists. Even an empty list is a distinct object. So, when you compare [] is [], the result is False because Python creates two separate empty list objects in memory.