
Python Tuples
Quiz
•
Computers
•
University
•
Practice Problem
•
Medium
Ilyas Ustun
Used 2+ times
FREE Resource
Enhance your content in a minute
15 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is a key characteristic of tuples that differentiates them from lists?
Tuples can only contain integers.
Tuples can only contain strings.
Tuples are immutable.
Tuples are mutable.
Answer explanation
A key characteristic of tuples is that they are immutable, meaning their contents cannot be changed after creation. This differentiates them from lists, which are mutable and allow modifications.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is a correct way to create a tuple with a single element?
t = 'p'
t = 'p',
t = ('p')
t = ('p',)
Answer explanation
To create a tuple with a single element, you must include a comma after the element. Thus, 't = ("p",)' is correct. The other options either create a string or do not properly define a tuple.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the result of the expression: tuple('spam') * 2?
('spam',)
('s', 'p', 'a', 'm', 's', 'p', 'a', 'm')
('s', 'p', 'a', 'm')
('spam', 'spam')
Answer explanation
The expression tuple('spam') creates a tuple with a single element 'spam'. When multiplied by 2, it repeats the contents of the tuple, resulting in ('s', 'p', 'a', 'm', 's', 'p', 'a', 'm'), which is the correct answer.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which function can be used to sort a tuple?
sort()
sorted()
arrange()
order()
Answer explanation
The function 'sorted()' is used to sort any iterable, including tuples, and returns a new sorted list. The 'sort()' method is for lists only, while 'arrange()' and 'order()' are not valid Python functions for sorting.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What error is raised when trying to modify a tuple?
IndexError
TypeError
ValueError
AttributeError
Answer explanation
Tuples are immutable in Python, meaning their contents cannot be changed. Attempting to modify a tuple raises a TypeError, indicating that an operation is not allowed on the data type.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the result of the following code: divmod(7, 3)?
(2, 1)
(1, 2)
(3, 1)
(2, 3)
Answer explanation
The divmod function returns a tuple containing the quotient and the remainder of the division. For divmod(7, 3), 7 divided by 3 gives a quotient of 2 and a remainder of 1, resulting in (2, 1). Thus, the correct answer is (2, 1).
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is a valid use of tuple assignment?
a, b = 1, 2, 3
a, b = '12'
a, b = (1, 2)
a, b = [1, 2]
Answer explanation
The correct choice is 'a, b = (1, 2)' because it uses tuple assignment correctly, unpacking the tuple (1, 2) into variables a and b. The other options either have too many values or are not tuples.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
11 questions
Youtube
Quiz
•
4th Grade - University
20 questions
Name The Disney Animation Films
Quiz
•
KG - University
10 questions
computer Networks
Quiz
•
University
19 questions
DBMS - Fundamentals
Quiz
•
University
10 questions
Industry 4.0 Unit 1
Quiz
•
University
13 questions
PWM y ADC con el MSP430F5529
Quiz
•
University
14 questions
Excel Bezüge und Funktionen - SUMME, MAX, MIN, MITTELWERT
Quiz
•
University
10 questions
Scratch
Quiz
•
KG - Professional Dev...
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
