Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn Python MEMBERSHIP OPERATORS in 8 minutes! ๐Ÿ”Ž
Play lesson

Python tutorial for beginners ๐Ÿ - Learn Python MEMBERSHIP OPERATORS in 8 minutes! ๐Ÿ”Ž

4.0 (0)
8 learners

What you'll learn

This course includes

  • 14.3 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#python #pythontutorial #pythonprogramming # Membership operators = used to test whether a value or variable is found in a sequence # (string, list, tuple, set, or dictionary) # 1. in # 2. not in # -------------------- # EXAMPLE 1 # -------------------- word = "APPLE" letter = input("Guess a letter in the secret word: ") if letter in word: print(f"There is a {letter}") else: print(f"{letter} was not found") # -------------------- # EXAMPLE 2 # -------------------- students = {"Spongebob", "Patrick", "Sandy"} student = input("Enter the name of a student: ") if student in students: print(f"{student} is in this class") else: print(f"{student} is NOT in this class") # -------------------- # EXAMPLE 3 # -------------------- grades = { "Sandy": 'A', "Squidward": 'B', "Spongebob": 'C', "Patrick": 'D' } student = input("Enter the name of a student: ") if student in grades: print(f"{student}'s grade is {grades[student]}.") else: print(f"{student} is not in the dictionary") # -------------------- # EXAMPLE 4 # -------------------- email = "[email protected]" if "@" in email and "." in email: print("Valid email") else: print("Invalid email")

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere