
Python Tuples

Quiz
•
Computers
•
University
•
Hard
Ilyas Ustun
FREE Resource
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.
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
Pre-Test Week 4

Quiz
•
University
20 questions
GirlsWhoML Workshop 0

Quiz
•
University
10 questions
Day 4

Quiz
•
12th Grade - University
12 questions
Quiz3

Quiz
•
University
15 questions
FLAT QUIZ

Quiz
•
University
10 questions
Tuple Quiz

Quiz
•
University
20 questions
DATABASE MANAGEMENT CT-1

Quiz
•
University
15 questions
SCRIPTING PROGRAMMING WITH PYTHON

Quiz
•
University
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
21 questions
Spanish-Speaking Countries

Quiz
•
6th Grade - University
20 questions
Levels of Measurements

Quiz
•
11th Grade - University
7 questions
Common and Proper Nouns

Interactive video
•
4th Grade - University
12 questions
Los numeros en español.

Lesson
•
6th Grade - University
7 questions
PC: Unit 1 Quiz Review

Quiz
•
11th Grade - University
7 questions
Supporting the Main Idea –Informational

Interactive video
•
4th Grade - University
12 questions
Hurricane or Tornado

Quiz
•
3rd Grade - University
7 questions
Enzymes (Updated)

Interactive video
•
11th Grade - University