Difference of two sets (A - B) Dry Run in PYTHON

Difference of two sets (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.

Difference of two sets (A - B) Program Code

# Difference of two sets (A - B)
A = {1, 2, 3, 4, 5, 6}
B = {4, 5, 6, 7, 8, 9}

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

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

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

# B - A (different result)
b_minus_a = B - A
print(f"B - A: {b_minus_a}")

# Method 3: difference_update (modifies in-place)
A_copy = A.copy()
A_copy.difference_update(B)
print(f"After difference_update: {A_copy}")

View the complete Sets programs page.

Program Console Difference of two sets (A - B) Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.