What is the correct way to define a tuple in Python?
A
tuple = [1, 2, 3] B
tuple = {1, 2, 3} C
tuple = (1, 2, 3) D
tuple = <1, 2, 3>
Analysis & Theory
Tuples are defined using parentheses: (1, 2, 3).
What is the key difference between a list and a tuple?
A
Tuples are slower B
Lists are immutable C
Tuples are immutable D
Tuples can’t store strings
Analysis & Theory
Tuples cannot be changed once created — they are immutable.
What will be the type of x = ('apple',) ?
A
str B
list C
tuple D
dict
Analysis & Theory
A trailing comma is required for a single-element tuple.
How do you access the second item in a tuple t = (10, 20, 30) ?
A
t[1] B
t(1) C
t{1} D
t.get(1)
Analysis & Theory
Tuples are indexed like lists. The second item is at index 1.
What happens if you try to change an element in a tuple?
A
The value is changed B
The item is added C
You get a TypeError D
It converts to a list
Analysis & Theory
Tuples are immutable, so any attempt to modify them raises a TypeError.
Which of the following creates an empty tuple?
A
() B
[] C
{} D
None
Analysis & Theory
Empty parentheses () create an empty tuple.
What is the result of len((1, 2, 3)) ?
A
2 B
3 C
1 D
Error
Analysis & Theory
len() returns the number of items in the tuple — in this case, 3.
Which method can you use to count items in a tuple?
A
tuple.count() B
tuple.length() C
tuple.counter() D
tuple.len()
Analysis & Theory
count(x) returns the number of times x appears in the tuple.
How can you convert a list to a tuple?
A
list() B
tuple[] C
tuple() D
convert.tuple()
Analysis & Theory
Use the built-in tuple() function to convert a list into a tuple.
Can a tuple contain elements of different data types?
A
No, only one data type allowed B
Yes, tuples can contain any data types C
Only integers allowed D
Only strings allowed
Analysis & Theory
Tuples can store a mix of data types like strings, integers, and lists.