20 Marks MCQ Test Paper On Tuples 11 TEST
20 Marks MCQ Test Paper On Tuples 11 TEST
Instructions:
Each question carries 1 mark.
Choose the correct option for each question.
1. What is the correct syntax to create a tuple in Python?
a) tuple = (1, 2, 3) b) tuple = [1, 2, 3] c) tuple = {1, 2, 3} d) tuple = 1, 2, 3
2. Which of the following statements will correctly create a list in Python?
a) list = (1, 2, 3) b) list = [1, 2, 3] c) list = {1, 2, 3} d) list = <1, 2, 3>
3. Which of the following is an immutable data type?
a) List b) Dictionary c) Tuple d) Set
4. How would you access the first element of the tuple my_tuple = (10, 20, 30)?
a) my_tuple[0] b) my_tuple(0) c) my_tuple[1] d) my_tuple[10]
5. What will be the output of the following code?
my_list = [1, 2, 3, 4]
my_list[1] = 10
print(my_list)
a) [1, 10, 3, 4] b) [10, 2, 3, 4] c) Error d) [1, 2, 3, 10]
6. Which method can be used to add an element to the end of a list?
a) list.append(x) b) list.add(x) c) list.insert(x) d) list.push(x)
7. How do you remove an element with the value 3 from the list my_list = [1, 2, 3, 4]?
a) my_list.remove(3) b) my_list.delete(3) c) my_list.pop(3) d) my_list.remove(3, 0)
8. Which of the following data types can be used as a key in a Python dictionary?
a) List b) Set c) String d) Dictionary
9. How would you access the value associated with the key 'name' in the dictionary
person = {'name': 'John', 'age': 30}?
a) person['name'] b) person(name) c) person.get('name') d) Both a and c
10. What is the output of the following code?
my_dict = {'a': 1, 'b': 2}
print(my_dict.get('c', 10))
a) 10 b) None c) KeyError d) 0
11. How do you add a new key-value pair to a dictionary?
a) my_dict.add('key', 'value') b) my_dict['key'] = 'value'
c) my_dict.insert('key', 'value') d) my_dict.put('key', 'value')
12. Which of the following will return the keys from a dictionary?
a) my_dict.keys() b) my_dict.items() c) my_dict.values() d) my_dict.get()
13. What will be the output of this code?
tuple1 = (1, 2, 3, 4)
tuple2 = tuple1 * 2
print(tuple2)
a) (1, 2, 3, 4, 1, 2, 3, 4) b) (1, 2, 3, 4, 2, 3, 4, 1) c) (1, 2, 3, 4) d) Error
14. What is the result of this code?
my_list = [1, 2, 3, 4, 5]
my_list[2:4] = [10, 11]
print(my_list)
a) [1, 2, 10, 11, 5] b) [1, 2, 10, 11]
c) [1, 2, 3, 4, 10, 11, 5] d) [10, 11, 1, 2, 3, 4]
15. What is the syntax for creating an empty dictionary in Python?
a) my_dict = [] b) my_dict = {} c) my_dict = set() d) my_dict = ()
16. Which of the following operations is not possible with a tuple?
a) Accessing elements using an index b) Slicing a tuple
c) Modifying an element d) Concatenating tuples
17. What will the following code print?
my_dict = {'x': 10, 'y': 20}
del my_dict['x']
print(my_dict)
a) {'x': 10, 'y': 20} b) {'y': 20} c) {'x': 10} d) KeyError
18. How would you combine two lists, list1 = [1, 2] and list2 = [3, 4]?
a) list1.concat(list2) b) list1 + list2
c) list1.append(list2) d) list1.extend(list2)
19. Which method is used to find the length of a list?
a) len(list) b) list.size() c) list.length() d) list.count()
20. What will be the output of the following code?
my_tuple = (1, 2, 3, 4, 5)
print(my_tuple[2:4])
a) (2, 3) b) (3, 4) c) (2, 3, 4) d) (1, 2, 3, 4)
Answer Key:
a) tuple = (1, 2, 3)
b) list = [1, 2, 3]
c) Tuple
a) my_tuple[0]
a) [1, 10, 3, 4]
a) list.append(x)
a) my_list.remove(3)
c) String
d) Both a and c
a) 10
b) my_dict['key'] = 'value'
a) my_dict.keys()
a) (1, 2, 3, 4, 1, 2, 3, 4)
b) my_dict = {}
c) Modifying an element
b) {'y': 20}
b) list1 + list2
a) len(list)
b) (3, 4)