Find index of element using index() method Dry Run in PYTHON

Find index of element using index() method 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.

Find index of element using index() method Program Code

# Find index of element using index()
colors = ("Red", "Green", "Blue", "Green", "Yellow")
print("Tuple:", colors)

# Find first occurrence
index_green = colors.index("Green")
print(f"Index of 'Green': {index_green}")

# Find with start and end parameters
index_green_after = colors.index("Green", 2)  # search from index 2
print(f"Index of 'Green' from index 2: {index_green_after}")

# Search within range
index_blue = colors.index("Blue", 1, 4)  # search indices 1-3
print(f"Index of 'Blue' between 1-4: {index_blue}")

# Handling ValueError
try:
    colors.index("Purple")
except ValueError as e:
    print(f"\nError: {e}")

View the complete Tuples programs page.

Program Console Find index of element using index() method Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.