Slicing Ruler
About this app
The numbers in a[i:j] are cuts between the cells: two handles for start and stop glide along a ruler with positive numbers above and negative ones below, the expression stays in sync, and the result appears exactly as in Python 3.13. a[1:3] gives two cells, a[2:100] is cut off, a[7] is an IndexError, a[5:2] is empty, a[5:1:-1] runs backwards. Plus index and del modes, strings with a TypeError on change, six tasks and predictions.
With explain mode: an AI tutor walks you through the app, points out what matters in the scene and answers your questions.
Cuts instead of positions
In Python the numbers in a[i:j] stand for cuts between the elements: cut k lies before element k. What comes out are the elements between the two cuts, j − i of them, which is why a[1:3] is only [2, 3]. Negative numbers count from the end; a[-1] is the last element. A missing bound means the start or the end. Python cuts off bounds outside the list: a[2:100] returns the rest without an error, while a single index such as a[7] is an IndexError. The third number is the step; with −1 Python reads backwards.
What the app shows
A row of cells shows the list or the string, with a ruler of positive numbers above and one of negative numbers below. Two handles stand for start and stop; the stop handle is hollow because this bound is excluded. In the cuts view the numbers sit on the edges, and for a negative step to the right of the cells. The expression stays in sync with the handles, and the result card shows the new list in Python notation with a sentence as on the slide below it. Error messages appear exactly as in Python, with an explanation.
Try it yourself
Drag the handles, type your own expression or roll a random one and predict what comes out. In index mode a pointer marks one cell, and outside the list the IndexError appears. In del mode elements really disappear and the remaining cells close up. Six tasks give a target such as [3, 4, 5] or 'world'; after a hit the app lists further expressions with the same result. Own lists of up to 12 values and strings of up to 16 characters are possible.
Frequently asked questions
- Why does a[1:3] return only two elements in Python?
- The numbers are cuts between the elements. a[1:3] takes everything between cut 1 and cut 3, i.e. the elements at positions 1 and 2. The stop bound is never included; the count is stop − start.
- What do negative indices like a[-1] mean?
- Negative numbers count from the end: a[-1] is the last element, a[-3:] the last three. Internally Python turns −k into n − k, so with seven elements −3 becomes 4.
- How do you reverse a list with slicing?
- With a negative step: a[::-1] returns the list backwards, a[5:1:-1] the elements from position 5 up to but not including 1. a[5:2] without a step does not reverse but is empty. A step of 0 raises a ValueError.
- What does the Slicing Ruler app show?
- A list or string as a row of cells with two rulers, draggable handles for start and stop, a step control, results as in Python 3.13, index and del modes, and six tasks with a list of solutions.
Subject: Computer science
More from Computer science
- Ackermann function
- Elevator simulator
- Binary workshop
- Binary versus linear search
- The Collatz problem
- Inside a CPU
- Swap the inside
- One frame in 16 milliseconds — how a game engine renders an image (3D)
A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps