0
0
Pythonprogramming~20 mins

Tuple methods in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Tuple Methods Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of count() method on a tuple
What is the output of this Python code?
t = (1, 2, 3, 2, 2, 4)
print(t.count(2))
Python
t = (1, 2, 3, 2, 2, 4)
print(t.count(2))
A3
B2
C1
D0
Attempts:
2 left
๐Ÿ’ก Hint
The count() method returns how many times the given value appears in the tuple.
โ“ Predict Output
intermediate
2:00remaining
Output of index() method with repeated elements
What will this code print?
t = ('a', 'b', 'c', 'b', 'd')
print(t.index('b'))
Python
t = ('a', 'b', 'c', 'b', 'd')
print(t.index('b'))
A2
B3
C4
D1
Attempts:
2 left
๐Ÿ’ก Hint
The index() method returns the first position of the value.
โ“ Predict Output
advanced
2:00remaining
What error does this code raise?
What error will this code produce?
t = (1, 2, 3)
print(t.index(4))
Python
t = (1, 2, 3)
print(t.index(4))
AValueError
BIndexError
CTypeError
DKeyError
Attempts:
2 left
๐Ÿ’ก Hint
The value 4 is not in the tuple, so index() cannot find it.
โ“ Predict Output
advanced
2:00remaining
Output of count() with no matching elements
What does this code print?
t = ('x', 'y', 'z')
print(t.count('a'))
Python
t = ('x', 'y', 'z')
print(t.count('a'))
A1
BNone
C0
DKeyError
Attempts:
2 left
๐Ÿ’ก Hint
count() returns zero if the value is not found.
๐Ÿง  Conceptual
expert
2:00remaining
Why can't you use append() on a tuple?
Which statement best explains why the tuple method append() does not exist?
ATuples do not support any methods at all.
BTuples are immutable, so their size and contents cannot be changed after creation.
Cappend() is only for strings, not tuples.
Dappend() is a method only for dictionaries.
Attempts:
2 left
๐Ÿ’ก Hint
Think about whether tuples can be changed after you make them.