MWZ

MINDWAREZONE

beginnerPython

How do the in and not in operators work?

Answer

Clear, interview-ready explanation

The in and not in operators are membership operators.

  • in returns True when a value exists in a sequence or collection.
  • not in returns True when a value does not exist in it.

They can be used with strings, lists, tuples, sets, dictionaries, and other iterable objects.

languages = ["Python", "PHP", "JavaScript"]

print("Python" in languages)
print("Java" not in languages)
            

Output:

True
True