MCQ Bank
To remove leading '#' characters, which should you use?
- A) s.lstrip('#')
- B) s.strip('#')
- C) s.rstrip('#')
- D) s.strip()
What does "HiThere".swapcase() return?
- A) "HItHere"
- B) "hItheRE"
- C) "hItHERE"
- D) "hitHERE"
What is the index of 'b' in lst = ['a', 'b', 'c']?
- A) 0
- B) 3
- C) 1
- D) 2
What does "cat".center(7, '-') return?
- A) 'cat'
- B) '--cat--'
- C) 'cat----'
- D) '---cat-'
What does lst[-1] return in lst = [10, 20, 30]?
- A) 20
- B) 30
- C) 10
- D) 0
What does lst.pop(1) do in [10, 20, 30]?
- A) Deletes 30
- B) Deletes 20
- C) Deletes 10
- D) Raises an error
Why are tuples considered immutable in Python?
- A) They support fewer data types
- B) Their size is fixed and cannot be altered
- C) They are stored in the heap memory
- D) They are designed to be mutable
Which method returns True if all characters in a string are alphabetic?
- A) isalnum()
- B) isalpha()
- C) isdigit()
- D) isnumeric()
Which method is used to add multiple items from another list?
- A) add()
- B) append()
- C) extend()
- D) insert()
What does "one,two,three".split(',' , 1) return?
- A) ['one,two', 'three']
- B) ['one']
- C) ['one', 'two,three']
- D) ['one', 'two', 'three']
What does s = "hello"; s[1:4] return?
- A) "ell"
- B) "elo"
- C) "hel"
- D) "llo"
Which statement is TRUE about lists?
- A) Duplicates are not allowed
- B) They must contain only integers
- C) Lists are immutable
- D) Lists allow duplicate and mixed-type elements
What is the difference between remove() and pop()?
- A) remove() uses index; pop() uses value
- B) remove() uses value; pop() uses index
- C) pop() removes first item
- D) Both are the same
What does the expression 10 not in (10, 20, 30) return?
- A) Error
- B) None
- C) False
- D) True
What is the output of lst[1] = 5 for lst = [1, 2, 3]?
- A) [1, 5, 3]
- B) [1, 2, 5]
- C) [5, 2, 3]
- D) [1, 5, 2, 3]
What is the return type of partition() and rpartition()?
- A) Set
- B) Tuple
- C) List
- D) String
Which method removes trailing whitespace only?
- A) lstrip()
- B) strip()
- C) rstrip()
- D) trim()
What does "xxhellox".strip('x') return?
- A) "hello"
- B) "xhellox"
- C) "xhello"
- D) "hellox"
What happens if a list passed to join() contains non-string elements?
- A) It converts them
- B) It skips them
- C) It raises an error
- D) It joins them with space
What does "123".isnumeric() return?
- A) Error
- B) True
- C) False
- D) None