Slice a tuple Dry Run in PYTHON

Slice a tuple 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.

Slice a tuple Program Code

# Slicing tuples (start:stop:step)
alpha = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
print("Original tuple:", alpha)

# Basic slices
print(f"alpha[2:6]: {alpha[2:6]}")     # indices 2 to 5
print(f"alpha[:4]: {alpha[:4]}")       # first 4 elements
print(f"alpha[5:]: {alpha[5:]}")       # from index 5 to end
print(f"alpha[:]: {alpha[:]}")         # whole tuple copy

# Step parameter
print(f"alpha[::2]: {alpha[::2]}")     # every 2nd element
print(f"alpha[1::2]: {alpha[1::2]}")   # every 2nd from index 1
print(f"alpha[::-1]: {alpha[::-1]}")   # reverse tuple

View the complete Tuples programs page.

Program Console Slice a tuple Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.