Welcome to the Python Tuples Quiz!
Tuples in Python are immutable, ordered collections that may retailer a number of gadgets of various knowledge varieties. In contrast to lists, tuples can’t be modified after creation, making them helpful for storing mounted knowledge. This quiz will take a look at your understanding of Python tuples, overlaying their properties, strategies, and customary use circumstances.
Every query is adopted by the right reply. Good luck!
Desk of Contents:
- Python quizzes for novices sequence
Tuples Quiz
Quiz Questions
Fundamental Ideas
- What’s a tuple in Python?
a) A mutable record
b) An immutable ordered assortment
c) A dictionary
d) A set
Reply
b) An immutable ordered assortment
- Which of the next appropriately creates a tuple?
a)tup = (1, 2, 3)
b)tup = [1, 2, 3]
c)tup = {1, 2, 3}
d)tup = "1, 2, 3"
Reply
a) tup = (1, 2, 3)
- What’s going to
sort((10,))
return?
a)<class 'record'>
b)<class 'tuple'>
c)<class 'int'>
d)<class 'dict'>
Reply
b) <class 'tuple'>
- Which technique can be utilized to depend occurrences of a component in a tuple?
a)depend()
b)index()
c)discover()
d)exists()
Reply
a) depend()
- How do you entry the final factor of a tuple
t = (5, 10, 15, 20)
?
a)t[-1]
b)t[3]
c)t[len(t) - 1]
d) The entire above
Reply
d) The entire above
Tuple Properties & Operations
- Can a tuple include duplicate values?
a) Sure
b) No
Reply
a) Sure
- Which of the next will create an empty tuple?
a)tup = ()
b)tup = tuple()
c)tup = {}
d) Each a and b
Reply
d) Each a and b
- Tuples are quicker than lists in Python.
a) True
b) False
Reply
a) True
- What’s going to occur for those who attempt to modify a tuple?
a) It’ll change the worth efficiently
b) It’ll elevate aTypeError
c) It’ll create a brand new tuple with the modified worth
d) It’ll return None
Reply
b) It’ll elevate a TypeError
- How are you going to concatenate two tuples
t1 = (1, 2)
andt2 = (3, 4)
?
a)t1 + t2
b)t1.prolong(t2)
c)t1.append(t2)
d)concat(t1, t2)
Reply
a) t1 + t2
Tuple Indexing & Slicing
- What’s the output of
t = (1, 2, 3, 4, 5)[1:4]
?
a)(2, 3, 4)
b)(1, 2, 3, 4)
c)(2, 3, 4, 5)
d)(3, 4, 5)
Reply
a) (2, 3, 4)
- What occurs for those who attempt
t[100]
ont = (10, 20, 30)
?
a) ReturnsNone
b) RaisesIndexError
c) Returns0
d) Prints nothing
Reply
b) Raises IndexError
- What’s the results of
t[::-1]
fort = (1, 2, 3, 4)
?
a)(1, 2, 3, 4)
b)(4, 3, 2, 1)
c)(1, 4, 3, 2)
d) Syntax error
Reply
b) (4, 3, 2, 1)
Tuple Strategies & Features
- How do you discover the size of a tuple
t = (1, 2, 3, 4, 5)
?
a)dimension(t)
b)size(t)
c)len(t)
d)depend(t)
Reply
c) len(t)
- Which perform converts an inventory right into a tuple?
a)record()
b)tuple()
c)set()
d)dict()
Reply
b) tuple()
- How do you verify if a component exists in a tuple?
a)exists()
b)in
c)discover()
d)comprises()
Reply
b) in
Superior Tuple Ideas
- What’s tuple unpacking?
a) Extracting values from a tuple into separate variables
b) Combining two tuples into one
c) Deleting parts from a tuple
d) Sorting a tuple
Reply
a) Extracting values from a tuple into separate variables
- What’s going to the next code output?
t = (1, 2, [3, 4])
t[2][0] = 99
print(t)
a) (1, 2, [99, 4])
b) (1, 2, [3, 4])
c) TypeError
d) (1, 2, 99, 4)
Reply
a) (1, 2, [99, 4])
- Which of the next is true?
a) Tuples use much less reminiscence than lists
b) Tuples are quicker than lists
c) Tuples are immutable
d) The entire above
Reply
d) The entire above
- Which built-in perform permits you to iterate over a tuple whereas retaining monitor of the index?
a)enumerate()
b)zip()
c)vary()
d)map()
Reply
a) enumerate()
How did you do? 🎯
- 18-20 appropriate → 🏆 Wonderful! You’re a Python features professional!
- 14-17 appropriate → 👍 Nice job! Hold practising.
- 10-13 appropriate → 🙂 Good, however there’s room for enchancment.
- Under 10 → 🤔 No worries! Overview the ideas and take a look at once more.