in operator
The operator that tests whether a value is contained in a string, list, tuple, set or dictionary, giving True or False.
In more detail
"ss" in "Mississippi" tests for a substring; 3 in nums for a list item; "key" in d for a dictionary key. not in is the negation. It is fast for sets and dictionaries and slower for long lists, which must be searched item by item.
Example
"a" in "cat" # TrueRelated terms
- comparison operator — An operator that compares two values and gives true or false, such as equal, not equal, less than or greater than.
- set (Python) — An unordered collection of distinct values, written {1, 2, 3} or made with set(), where each value appears only once.
- dictionary — A Python collection that stores values under keys, written in curly brackets, such as {"tea": 250}.
Taught in
- How Python Runs Your Code — Hands-on Python: Complete Video Course & Book
- Installing Python On Linux — Hands-on Python: Complete Video Course & Book
- The String Format Method — Hands-on Python: Complete Video Course & Book
- If Else, And Conditional Expressions — Hands-on Python: Complete Video Course & Book
- More String Methods — Hands-on Python: Complete Video Course & Book
- Chapter Three In One Sitting — Hands-on Python: Complete Video Course & Book
- Literals, Names And Four Number Bases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Lists: Slices, Methods And Aliases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Tuples, And The Comma That Makes Them — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Dictionaries: Keys, Values And Items — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- math, random And platform — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Modules Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Characters As Numbers — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comparing, Slicing And Never Changing — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- String Methods The Exam Picks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Strings Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Special Methods: __str__, __eq__ And Friends — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Object-Oriented Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep