Program Console Vignaankosh.com
Execution Panel
Console is empty.
Merge two sets (union) 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.
# Merge two sets (Union operation)
set1 = {10, 20, 30, 40}
set2 = {30, 40, 50, 60}
print("Set1:", set1)
print("Set2:", set2)
# Method 1: Using | operator
merged = set1 | set2
print(f"\nUnion using |: {merged}")
# Method 2: Using union() method
merged2 = set1.union(set2)
print(f"Using union(): {merged2}")
# Method 3: Using update() (modifies set1)
set1_copy = set1.copy()
set1_copy.update(set2)
print(f"Using update(): {set1_copy}")
# Method 4: Unpacking
merged4 = {*set1, *set2}
print(f"Using unpacking: {merged4}")