Class 3: Data Structures in Python
Python Data Structures Quiz
Test your Python data structures knowledge with these coding questions:
Time Remaining: 03:20
1. How do you create a list with integers 1, 2, and 3 in Python?
A) list = [1, 2, 3] B) list = (1, 2, 3) C) list = {1, 2, 3} D) list = {1: 2, 2: 3}2. Which of the following is immutable in Python?
A) List B) Dictionary C) Tuple D) Set3. How do you access the first element of a list `my_list`?
A) my_list[0] B) my_list[1] C) my_list[-1] D) my_list[2]4. How can you add an item to a set `my_set`?
A) my_set.append(item) B) my_set.add(item) C) my_set.insert(item) D) my_set.push(item)5. How can you create an empty dictionary in Python?
A) dict = [] B) dict = () C) dict = {} D) dict = set()6. Which method removes an item with a specific key from a dictionary?
A) del dict[key] B) dict.pop(key) C) dict.remove(key) D) dict.delete(key)7. Which operator can be used to combine two sets?
A) + B) & C) | D) ^8. How do you convert a list to a set to remove duplicates?
A) set(list) B) unique(list) C) list(set) D) remove_duplicates(list)9. Which of the following is a key-value pair structure in Python?
A) List B) Tuple C) Dictionary D) Set10. How do you access the value associated with a key in a dictionary?
A) dict.key B) dict[key] C) dict.getValue(key) D) dict.access(key)