CodeStudy.net
Toggle Menu
Home
Online Java Compiler
Tutorials
Java Tutorial
Python Tutorial
SQL Database Design
Blog
All Posts
Python Data Structures
Assess your knowledge of lists,tuples,sets,and dictionaries.
1. Which data structure is immutable in Python?
List
Tuple
Dictionary
Set
2. Which of the following are mutable data structures in Python?
List
Tuple
Dictionary
Set
3. A Python list can contain elements of different data types.
True
False
4. What is the method used to add an element to the end of a list?
5. Which data structure uses key-value pairs for storage?
List
Tuple
Dictionary
Set
6. Which operations can be performed on a set?
add()
remove()
append()
pop()
7. Dictionaries in Python 3.6 and earlier preserve the insertion order of keys.
True
False
8. What is the output of [1, 2, 3] + [4, 5]?
[1, 2, 3, 4, 5]
[5, 7]
(1, 2, 3, 4, 5)
Error
9. Name the data structure that cannot have duplicate elements.
10. Which data structures allow accessing elements by index?
List
Tuple
String
Set
11. Tuples can be modified after creation.
True
False
12. Which method removes and returns an arbitrary element from a set?
remove()
discard()
pop()
clear()
13. What is the output of len({'a': 1, 'b': 2})?
14. Which are valid dictionary key types?
String
List
Integer
Tuple with mutable elements
15. The 'in' operator checks for the presence of a value in a dictionary by default.
True
False
16. What does list.extend([1, 2]) do compared to list.append([1, 2])?
Both add elements 1 and 2
extend adds [1, 2] as a single element; append adds elements 1 and 2
append adds [1, 2] as a single element; extend adds elements 1 and 2
Both add [1, 2] as a single element
17. What data structure is created with curly braces containing comma-separated values (no key-value pairs)?
18. Which methods are available for both lists and tuples?
append()
count()
index()
sort()
19. Sets are ordered data structures in Python 3.7+.
True
False
20. Which data structure provides O(1) average time complexity for membership checks ('in' operator)?
List
Tuple
Set
String
Reset
Answered 0 of 0 — 0 correct