Symmetric difference (A △ B) Dry Run in PYTHON

Symmetric difference (A △ B) 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.

Symmetric difference (A △ B) Program Code

# Symmetric difference (elements in either, but not both)
A = {11, 22, 33, 44}
B = {33, 44, 55, 66}

print("Set A:", A)
print("Set B:", B)

# Method 1: ^ operator
sym_diff = A ^ B
print(f"\nA ^ B: {sym_diff}")

# Method 2: symmetric_difference() method
sym_method = A.symmetric_difference(B)
print(f"A.symmetric_difference(B): {sym_method}")

# Method 3: (A - B) | (B - A)
manual = (A - B) | (B - A)
print(f"(A-B) | (B-A): {manual}")

# Method 4: symmetric_difference_update (modifies A)
A_copy = A.copy()
A_copy.symmetric_difference_update(B)
print(f"After symmetric_difference_update: {A_copy}")

View the complete Sets programs page.

Program Console Symmetric difference (A △ B) Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.