Recall & Review
beginner
What does the
count() method do in a tuple?The
count() method returns how many times a specific value appears in the tuple.Click to reveal answer
beginner
What is the purpose of the
index() method in a tuple?The
index() method returns the first position (index) of a specified value in the tuple. If the value is not found, it raises a ValueError.Click to reveal answer
beginner
Can you add or remove items from a tuple using tuple methods?
No, tuples are unchangeable (immutable). You cannot add, remove, or change items using tuple methods.
Click to reveal answer
beginner
Example: What is the output of
(1, 2, 3, 2).count(2)?The output is
2 because the number 2 appears twice in the tuple.Click to reveal answer
beginner
Example: What does
("a", "b", "c").index("b") return?It returns
1 because "b" is at index 1 in the tuple (counting starts at 0).Click to reveal answer
Which tuple method tells you how many times a value appears?
✗ Incorrect
The
count() method counts how many times a value appears in a tuple.What does
index() return when called on a tuple?✗ Incorrect
index() returns the first position (index) of the specified value.What happens if you try to change a tuple item using a method?
✗ Incorrect
Tuples are immutable, so trying to change an item causes an error.
What is the output of
(4, 5, 4, 4).count(4)?✗ Incorrect
The number 4 appears three times in the tuple.
If
t = ("x", "y", "z"), what does t.index("y") return?✗ Incorrect
"y" is at index 1 in the tuple.
Explain how the
count() and index() methods work on tuples.Think about what each method returns when you look for a value.
You got /3 concepts.
Why can't you add or remove items from a tuple using methods?
Consider what 'immutable' means for tuples.
You got /3 concepts.