File I/O in Python
15 questions · 12 min · Medium
Test your knowledge of Python lists, tuples, and sets, including their properties, indexing, mutability, common methods, operations, and practical usage.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. List
Lists are ordered and mutable collections that can contain duplicate elements.
C. [1, 2, 3]
Square brackets are used to create list literals in Python.
B. Tuple
Tuples are immutable, meaning their elements cannot be changed after the tuple is created.
C. (1, 2, 3)
Parentheses are commonly used for tuple literals, although commas are what define tuple packing.
C. Set
A set contains unique elements, so duplicate values are represented only once.
C. set()
set() creates an empty set. {} creates an empty dictionary.
B. append()
The append() method adds one element to the end of a list.
C. pop()
The pop() method removes and returns an item by index, defaulting to the last item when no index is supplied.
A. numbers[0]
Python sequences use zero-based indexing, so index 0 refers to the first element.
C. add()
The add() method inserts a single element into a set.
C. Intersection
Set intersection returns elements common to both sets and can be performed with & or intersection().
B. |
The | operator performs set union, combining the unique elements from both sets.
C. Tuples are immutable sequences
Tuples are ordered, immutable sequences and can contain duplicate values and different data types.
B. The set keeps only one occurrence
Sets contain unique elements, so adding an element that is already present does not create a duplicate.
C. Lists are mutable while tuples are immutable
The key distinction is that list contents can be changed after creation, while tuple contents cannot be changed.