What does the count() method do in a tuple?
Returns the number of occurrences of a specified value in the tuple.
What is the purpose of the index() method?
Returns the first index of a specified value in the tuple.
True or false: Tuples are mutable in Python.
FALSE
Tuples are immutable, meaning their elements cannot be changed after creation.
Fill in the blank: The len() function returns the _______ of a tuple.
number of elements
What is a tuple?
An ordered collection of elements that is immutable.
What does tuple packing mean?
Assigning multiple values to a tuple in a single statement.
What does tuple unpacking allow you to do?
Assign elements of a tuple to multiple variables in one go.
True or false: Tuples can contain duplicate elements.
TRUE
What is the result of t = (1, 2, 3) and t.index(2)?
Returns 1, the index of the first occurrence of 2.
Fill in the blank: A tuple can be created using _______ parentheses.
round
What happens if you try to modify a tuple?
It raises a TypeError since tuples are immutable.
Define nested tuples.
Tuples that contain other tuples as their elements.
What does t.count(1) return if t = (1, 2, 1)?
Returns 2, as 1 appears twice.
True or false: You can concatenate two tuples.
TRUE
Use the + operator to concatenate tuples.
What is the output of (1, 2) + (3, 4)?
Returns (1, 2, 3, 4).
Fill in the blank: The slice operation can be used on tuples to get _______.
sub-tuples
What does t[::-1] do if t = (1, 2, 3)?
Reverses the tuple, returning (3, 2, 1).
What is the difference between a list and a tuple?
Lists are mutable; tuples are immutable.
What is the output of len((1, 2, 3))?
Returns 3, the number of elements in the tuple.
True or false: Tuples can hold mixed data types.
TRUE
What does the * operator do with tuples?
Repeats the tuple elements a specified number of times.
What is the result of (1, 2) * 3?
Returns (1, 2, 1, 2, 1, 2).
Fill in the blank: A tuple with one element must include a _______ after the element.
comma
What does t = (1,) create?
A tuple with a single element, 1.