MCQ Bank
Which method checks how many times a word appears in a string?
- A) count()
- B) find()
- C) index()
- D) match()
Which list method removes the first occurrence of a value?
- A) pop()
- B) del
- C) remove()
- D) discard()
If skills = "Python|Java|C++|Machine Learning", what is the result of skills.split("|")?
- A) Python, Java, C++
- B) Python, Java
- C) Python
- D) Python, Java, C++, Machine Learning
What is the result of the following operation? set1 = {1, 2, 3} set2 = {2, 3, 4} print(set1 & set2)
- A) {1, 4}
- B) {2, 3}
- C) { }
- D) {2, 3, 4}
What will participants[:3] return if participants = [('A',1), ('B',2), ('C',3), ('D',4)]?
- A) [('A',1), ('B',2), ('C',3)]
- B) [('A',1), ('C',3), ('D',4)]
- C) [('B',2), ('C',3), ('D',4)]
- D) [('A',1)]
Which key function allows sorting a list of numbers based on absolute value?
- A) key=abs
- B) key=float
- C) key=int
- D) key=str
What will be the output of the following code? s = {10, 20, 30} s.discard(40) print(s)
- A) {10, 20, 30}
- B) None
- C) {10, 20, 30, 40}
- D) Error: 40 not found in set
Which one of the following methods splits a multi-line string into a list of lines?
- A) breaklines()
- B) lines()
- C) split(" ")
- D) splitlines()
What will bio.replace("ai", "Artificial Intelligence", 1) do?
- A) Do nothing if "ai" is in lowercase
- B) Replace only the first occurrence of "ai"
- C) Replace "ai" in each word
- D) Replace all "ai" with "Artificial Intelligence"
What does the strip() method do to a string?
- A) Removes leading and trailing whitespace
- B) Converts to uppercase
- C) Splits the string into a list
- D) Removes all characters
Which operator is used for variable-length unpacking in Python?
- A) **
- B) *
- C) &
- D) //
What is the result of the following operation? (1, 2) + (3, 4)
- A) (1, 2, 3, 4)
- B) (4, 6)
- C) [1, 2, 3, 4]
- D) (1, 2)(3, 4)
what is the result of participants[0] if participants = [('Zara', 85), ('Ahmed', 90)]?
- A) ('Zara', 85)
- B) ['Zara', 85]
- C) 'Zara'
- D) 85
What is a key characteristic of a recursive function?
- A) It returns a tuple
- B) It always use lambda
- C) It calls itself within its body
- D) It contains a while loop
Which method adds a single element to a set?
- A) add()
- B) push()
- C) append()
- D) insert()
What does the strip() method do in Python?
- A) Removes leading and trailing whitespace
- B) Converts lowercase to uppercase
- C) Removes all occurrences of a character
- D) Replaces all spaces with tabs
How can we access the last element of a tuple?
- A) tuple[len]
- B) tuple[-1]
- C) tuple[length]
- D) tuple.last()
How do you sort a list ignoring case sensitivity?
- A) sorted(list, key=abs)
- B) list.sort()
- C) list.sort(reverse=True)
- D) sorted(list, key=str.lower)
Which of the following is used to extract the first letter of a string s?
- A) s[2]
- B) s[1]
- C) s[-1]
- D) s[0]
What does the count("and") method return when applied on a string?
- A) Removes the word "and" from a string
- B) Number of words in a string
- C) Number of times "and" appears in a string
- D) Position of the word "and" in a string