Recall & Review
beginner
What is tuple indexing in Python?
Tuple indexing means accessing individual elements of a tuple using their position number, starting from 0 for the first element.
Click to reveal answer
beginner
How do you access the last element of a tuple named
t?You use negative indexing:
t[-1] gives the last element of the tuple.Click to reveal answer
beginner
What does tuple slicing do?
Tuple slicing extracts a part of the tuple by specifying a start and end position, returning a new tuple with those elements.
Click to reveal answer
beginner
Explain the syntax of tuple slicing with an example.
Syntax:
tuple[start:end] extracts elements from index start up to but not including end. For example, t = (10, 20, 30, 40); t[1:3] returns (20, 30).Click to reveal answer
beginner
Can you change an element of a tuple using indexing?
No, tuples are immutable. You cannot change elements by indexing. You can only read elements.
Click to reveal answer
What will
t[2] return if t = (5, 10, 15, 20)?✗ Incorrect
t[2] accesses the element at index 2, which is the third element, 15.What does
t[-2] return for t = (1, 2, 3, 4, 5)?✗ Incorrect
Negative index -2 means the second last element, which is 4.
What is the result of
t[1:4] if t = (7, 8, 9, 10, 11)?✗ Incorrect
Slicing from index 1 to 4 extracts elements at positions 1, 2, and 3: (8, 9, 10).
Which of these is NOT a valid way to slice a tuple
t?✗ Incorrect
Parentheses with colon like
t(1:3) is invalid syntax. Use square brackets for slicing.Can you assign a new value to
t[0] if t = (1, 2, 3)?✗ Incorrect
Tuples cannot be changed after creation; they are immutable.
Describe how to access elements in a tuple using indexing and negative indexing.
Think about counting positions from the start and from the end.
You got /3 concepts.
Explain how tuple slicing works and what the result looks like.
Imagine cutting a piece from a string or a list.
You got /4 concepts.