Access tuple elements using index Dry Run in PYTHON

Access tuple elements using index is an interactive PYTHON dry run visualizer from the Tuples 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.

Access tuple elements using index Program Code

# Access tuple elements using positive indexing
colors = ("Red", "Green", "Blue", "Yellow", "Purple")
print("Tuple:", colors)

# Access by index
print(f"Index 0 (first): {colors[0]}")
print(f"Index 2 (third): {colors[2]}")
print(f"Index 4 (last): {colors[4]}")

# Access with variable
idx = 3
print(f"Index {idx}: {colors[idx]}")

# Trying to modify - will cause error
try:
    colors[0] = "Orange"
except TypeError as e:
    print(f"\nError: {e}")

View the complete Tuples programs page.

Program Console Access tuple elements using index Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.