MCQ Bank
Which of the following removes the last element of a list?
- A) list.pop()
- B) del list[0]
- C) list.remove()
- D) list.clear()
Which statement replaces the second and third elements of a list with new values "x" and "y"?
- A) list[2:3] = [x, y]
- B) list[1:3] = [x, y]
- C) list.replace(x, y)
- D) list.insert(x, y)
Which of the following is a valid tuple concatenation?
- A) tuple1.append(tuple2)
- B) tuple1 + tuple2
- C) tuple1.extend(tuple2)
- D) tuple1.add(tuple2)
Which of the following is the correct way to define a Python function that takes two parameters?
- A) def func(x, y)
- B) func(x, y)
- C) function func(x, y)
- D) function(x, y)
Which method converts "bachelor of science" to "Bachelor Of Science"?
- A) format()
- B) title()
- C) upper()
- D) capitalize()
Which of the following checks whether an "apple" is present in the set "Fruits"?
- A) 'apple' exists in fruits
- B) find(fruits, 'apple')
- C) fruits.has('apple')
- D) 'apple' in fruits
What is the output of "hello world".upper()?
- A) Hello world
- B) HELLO WORLD
- C) hello World
- D) Hello World
What is the output of len((10, 20, 30))?
- A) 3
- B) 2
- C) 1
- D) 0
Which method raises an error if the specified element is not present in the set?
- A) discard()
- B) clear()
- C) pop()
- D) remove()
What is the result of set([True, 1, False, 0])?
- A) {True, False, 1, 0}
- B) {}
- C) {True, False}
- D) {1, 0}
What is the result of marks[:3] if marks = [85, 90, 78, 92, 85]?
- A) [85, 90, 78]
- B) [78, 92, 85]
- C) [85, 90]
- D) [92, 85]
What is the result of name, *details = ("Areeba", 87, "Passed")?
- A) name = "Areeba", details = ["Passed"]
- B) name = 87, details = ["Passed"]
- C) name = "Areeba", details = [87, "Passed"]
- D) name = "Passed", details = [87]
Which built-in function converts a number to a string in Python?
- A) int()
- B) string()
- C) float()
- D) str()
What is the output of sorted(names, reverse=True) if names = ['zain', 'bilal', 'ahmed']?
- A) ['ahmed', 'bilal', 'zain']
- B) ['bilal', 'zain', 'ahmed']
- C) ['zain', 'ahmed', 'bilal']
- D) ['zain', 'bilal', 'ahmed']
What does skills.split("|") return if skills = "Python|Java|SQL"?
- A) ['P', 'y', 't', 'h', 'o', 'n']
- B) ['Python', 'Java', 'SQL']
- C) "Python Java SQL"
- D) ('Python', 'Java', 'SQL')
What will len(str(1234)) return?
- A) 1
- B) 2
- C) 3
- D) 4
What does list.copy() do?
- A) Creates a reference to the same list
- B) Deletes the list
- C) Creates a shallow copy of the list
- D) Creates a deep copy
Which symbol represents a newline in Python strings?
- A) /n
- B) \\
- C) \t
- D) \n
In Python user-defined functions, what does the return keyword do?
- A) It stops the program execution
- B) It prints output to the console
- C) It sends the result back to the caller function
- D) It defines a function
What is the output of "hello world".capitalize()?
- A) Hello world
- B) Hello World
- C) hello World
- D) HELLO WORLD