Find length of set (number of elements) Dry Run in PYTHON

Find length of set (number of elements) 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.

Find length of set (number of elements) Program Code

# Find length of set using len()
my_set = {5, 10, 15, 20, 25, 30, 35}
print("Set:", my_set)
print(f"Length: {len(my_set)}")

# Length after adding duplicates (ignored)
my_set.add(5)  # duplicate
my_set.add(40)
print(f"\nAfter adding duplicate and 40: {my_set}")
print(f"New length: {len(my_set)}")

# Empty set length
empty = set()
print(f"\nEmpty set length: {len(empty)}")

# Manual counting using loop
count = 0
for item in my_set:
    count += 1
print(f"Manual count: {count}")

View the complete Sets programs page.

Program Console Find length of set (number of elements) Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.