MCQ Bank
Which syntax is used to convert a tuple to a list?
- A) tuple = list()
- B) tuple(list)
- C) list = tuple()
- D) list(tuple)
What does the index() method do in a tuple?
- A) Removes an element by index
- B) Inserts an element at a given index
- C) Returns the index of the first matching element
- D) Changes the value at a specific index
What is the output of below code? print("i love python and java and AI.".count("and"))
- A) 3
- B) 4
- C) 1
- D) 2
Which of the following correctly performs a union operation on two sets A and B in Python?
- A) A & B
- B) A - B
- C) A ^ B
- D) A | B
What is the result of the following code? s = {1, 2} s.update([3, 4], {5}) print(s)
- A) {1, 2, [3, 4], {5}}
- B) {1, 2, 3, 4, 5}
- C) {1, 2, [3, 4], 5}
- D) Error
Which list method is used to add multiple elements at the end of a list?
- A) append()
- B) extend()
- C) add()
- D) insert()
What does the len("Python") return?
- A) 7
- B) 5
- C) 6
- D) 8
What will be the output of students[0] if students = ["Ali", "Sara", "John", "Zain"]?
- A) John
- B) Sara
- C) Ali
- D) Zain
Which method is used to convert a string like "muhammad ali" to "Muhammad Ali"?
- A) capitalize()
- B) propercase()
- C) title()
- D) upper()
Which method is used to add a single element to a Python set?
- A) insert()
- B) add()
- C) append()
- D) extend()
What will be the result of {"Ali", "Sana"} & {"Sana", "Hamza"} in Python?
- A) {'Sana'}
- B) {'Ali'}
- C) {'Hamza'}
- D) {'Ali', 'Sana', 'Hamza'}
Which set operation returns all unique elements from two sets?
- A) Difference
- B) Symmetric Difference
- C) Union
- D) Intersection
Which Python data structure automatically removes duplicate entries from a list?
- A) Set
- B) Tuple
- C) Dictionary
- D) List
Which method is used to safely access a value in a dictionary without causing a KeyError if the key does not exist?
- A) get()
- B) index()
- C) find()
- D) search()
Which operator is used to find elements present in one set but not in another?
- A) &
- B) -
- C) |
- D) *
Which statement correctly checks if the key "ML101" exists in a dictionary named faculty?
- A) faculty.contains("ML101")
- B) "ML101" in faculty
- C) faculty.exists("ML101")
- D) faculty.has("ML101")
Which method can add multiple key-value pairs to an existing dictionary at once?
- A) update()
- B) merge()
- C) append()
- D) add()
What is the output of sorted(names, reverse=True) if names = ['zain', 'bilal', 'ahmed']?
- A) ['bilal', 'zain', 'ahmed']
- B) ['zain', 'bilal', 'ahmed']
- C) ['zain', 'ahmed', 'bilal']
- D) ['ahmed', 'bilal', 'zain']
What does the len("Python") return?
- A) 5
- B) 8
- C) 6
- D) 7
Which of the following removes the last element of a list?
- A) list.pop()
- B) list.remove()
- C) del list[0]
- D) list.clear()