MCQ Bank
What is the output of the below code? name = "Ali" print(f"Hello, {name}!")
- A) Hello, name!
- B) Hello, Ali!
- C) Hello, {name}!
- D) f"Hello, Ali!"
What is the output of "apple".replace("p", "*")?
- A) 'ap*le'
- B) 'apple'
- C) 'a**le'
- D) 'a*ple'
What does lst[:2] return in [10, 20, 30]?
- A) [10, 20]
- B) [30]
- C) [10, 20, 30]
- D) [20, 30]
What does " abc ".strip() return?
- A) " abc "
- B) " abc"
- C) "abc "
- D) "abc"
What is the output of "banana".count("a")?
- A) 1
- B) 2
- C) 3
- D) 4
Which operator is used to check if a substring exists in a string?
- A) has
- B) in
- C) exists
- D) within
What does "hello".rfind("l") return?
- A) 1
- B) 2
- C) 4
- D) 3
What does lst.append([3, 4]) do?
- A) Adds 3 and 4 separately
- B) Adds 3 only
- C) Adds the list as a single item
- D) Replaces last item
What is the output of lst[::2] for [0, 1, 2, 3, 4]?
- A) [2, 4]
- B) [1, 2, 3]
- C) [0, 2, 4]
- D) [1, 3]
What is the correct way to define a list in Python?
- A) mylist = (1, 2, 3)
- B) mylist = {1, 2, 3}
- C) mylist = <1, 2, 3>
- D) mylist = [1, 2, 3]
What does f"{10:>5}" produce?
- A) '10 '
- B) '0010'
- C) ' 10'
- D) '10'
Identify the syntax error in the below code: s = "abc" print(s[3])
- A) You need to convert s to list first
- B) Strings can't be indexed
- C) Index 3 is out of range
- D) Missing comma in print
What does "hello world".count("l", 3) return?
- A) 0
- B) 3
- C) 1
- D) 2
What does lst[-2:] return for lst = [5, 10, 15]?
- A) [5, 10]
- B) [ ]
- C) [10, 15]
- D) [15]
What does "apple".find("p") return?
- A) 4
- B) 2
- C) 1
- D) 3
Which method creates a list from a tuple?
- A) array()
- B) list()
- C) convert()
- D) tolist()
Which of the following empties a list?
- A) lst.clear()
- B) lst.pop()
- C) del lst[0]
- D) lst.remove(0)
Which method can be used to change an element in a tuple?
- A) Use the append() method
- B) Convert the tuple to a list, modify it, and convert back
- C) Use the replace() method
- D) Direct assignment
What is the result of "hello123".isalnum()?
- A) None
- B) Error
- C) False
- D) True
What is the result of lst[1:3] = [9, 10] on [1, 2, 3, 4]?
- A) [9, 10]
- B) [1, 2, 9, 10, 4]
- C) [1, 9, 10, 3, 4]
- D) [1, 9, 10, 4]