Add elements using add() method Dry Run in PYTHON

Add elements using add() method 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.

Add elements using add() method Program Code

# Add single element using add()
colors = {"Red", "Blue"}
print("Original:", colors)

# Add single element
colors.add("Green")
print("After add('Green'):", colors)

# Adding duplicate does nothing
colors.add("Red")
print("After add('Red') duplicate:", colors)

# Adding different types
numbers = {1, 2, 3}
numbers.add(4)
numbers.add(4)  # duplicate - ignored
print(f"\nNumbers: {numbers}")

View the complete Sets programs page.

Program Console Add elements using add() method Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.