Check element existence using 'in' operator Dry Run in PYTHON

Check element existence using 'in' operator is an interactive PYTHON dry run visualizer from the Sets programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Check element existence using 'in' operator Program Code

# Check membership using 'in' operator
fruits = {"Apple", "Banana", "Cherry", "Mango", "Orange"}
print("Set:", fruits)

# Check if element exists
print(f"Is 'Apple' in set? {'Apple' in fruits}")
print(f"Is 'Grape' in set? {'Grape' in fruits}")
print(f"Is 'Kiwi' NOT in set? {'Kiwi' not in fruits}")

# Membership is O(1) - very fast!
search = input("\nEnter fruit to search: ")
if search in fruits:
    print(f" {search} found in set!")
else:
    print(f" {search} not found")

# Example with numbers
nums = {1, 2, 3, 4, 5}
print(f"\n3 in nums: {3 in nums}")
print(f"10 in nums: {10 in nums}")

View the complete Sets programs page.

Program Console Check element existence using 'in' operator Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.