MCQ Bank
What is tuple packing in Python?
- A) Assigning values from a tuple to variables
- B) Grouping values into a tuple
- C) Flattening a tuple into a list
- D) Deleting a tuple
Which of the following is the correct way to extract a sub-tuple from the tuple t = (10, 20, 30, 40, 50)?
- A) t[1, 3]
- B) t[1:3]
- C) t{1, 3}
- D) t(1, 3)
What is the output of "Mississippi".count("ss")?
- A) 2
- B) 1
- C) 4
- D) 3
Which of the following is correct for unpacking a tuple t = (1, 2, 3) into variables?
- A) a = b = c = t
- B) a, b, c = t
- C) a, b = t
- D) a, b, c = (1, 2)
How can a tuple be extended by adding another tuple "(1,2)" to it?
- A) tuple + (1,2)
- B) tuple.append((1,2))
- C) tuple.extend((1,2))
- D) tuple.add((1,2))
What is the result of the following operation: (1, 2) + (3, 4)?
- A) (4, 6)
- B) (1, 2, 3, 4)
- C) (4, 6, 3, 4)
- D) (1, 2) (3, 4)
What will the code a, *b = (1, 2, 3, 4) do?
- A) Error
- B) Assign a = (1,) and b = (2, 3, 4)
- C) Assign a = (1, 2) and b = (3, 4)
- D) Assign a = 1 and b = (2, 3, 4)
What does the following code return? "hi".ljust(5)
- A) ' hi'
- B) ' hi '
- C) 'hi '
- D) 'hi'
What does "python programming".title() return?
- A) "python Programming"
- B) "Python Programming"
- C) "Pythonprogramming"
- D) "Python programming"
Which method is used to right-align a string within a given width?
- A) rjust()
- B) center()
- C) justify()
- D) ljust()
What is the result of "Python" in "I love Python programming"?
- A) Programming
- B) True
- C) False
- D) Python
What is the output of below code? lst = [1, 2, 3, 4] lst[1:3]
- A) [1, 2, 3]
- B) [3, 4]
- C) [2, 3, 4]
- D) [2, 3]
How do you access the 3rd character of string s = "Python"?
- A) s[2]
- B) s[3:4]
- C) s[3]
- D) s[-3]
Which escape sequence moves the cursor to the next line?
- A) \f
- B) \t
- C) \n
- D) \r
What does "apple".find("p") return?
- A) 4
- B) 3
- C) 1
- D) 2
What does " abc ".strip() return?
- A) " abc"
- B) "abc"
- C) "abc "
- D) " abc "
What is the difference between remove() and pop()?
- A) Both are the same
- B) pop() removes first item
- C) remove() uses value; pop() uses index
- D) remove() uses index; pop() uses value
What is the result of "hello123".isalnum()?
- A) True
- B) Error
- C) None
- D) False
What is tuple packing in Python?
- A) Grouping values into a tuple
- B) Deleting a tuple
- C) Assigning values from a tuple to variables
- D) Flattening a tuple into a list
What is the output of "apple".replace("p", "*")?
- A) 'apple'
- B) 'ap*le'
- C) 'a**le'
- D) 'a*ple'