iGET

Python Programming - MCQ Practice Questions

Core Python MCQs — syntax, data types, OOP, libraries for placements & IT exams.

188 questions | 100% Free

Q.81Medium

What is the purpose of the __init__.py file in a Python package directory?

Q.82Medium

What will be the output of the following code? def add(a, b): return a + b result = add print(result(3, 4))

Q.83Medium

Which of the following correctly imports only the sqrt function from the math module?

Q.84Medium

What will be the output of the following code? def counter(): count = 0 def increment(): nonlocal count count += 1 return count return increment c = counter() print(c()) print(c()) print(c())

Q.85Medium

What will be the output of the following code? import math as m print(m.floor(4.7)) print(m.ceil(4.2))

Q.86Medium

What will be the output of the following code? def apply(func, value): return func(value) result = apply(lambda x: x ** 2, 5) print(result)

Q.87Medium

What does the regular expression pattern `^\d{3}-\d{4}$` match?

Q.88Medium

Which of the following `re` module functions returns all non-overlapping matches of a pattern in a string as a list of strings?

Q.89Medium

What is the output of the following code? ```python import re result = re.sub(r'\s+', '-', 'Hello World Python') print(result) ```

Q.90Medium

What does the `re.IGNORECASE` (or `re.I`) flag do when used in a regular expression?

Q.91Medium

What is the difference between `re.match()` and `re.search()` in Python?

Q.92Medium

What will the following code print? ```python import re pattern = r'(\w+)@(\w+)\.com' m = re.search(pattern, 'Contact: user@example.com today') if m: print(m.group(1), m.group(2)) ```

Q.93Medium

Which regular expression pattern correctly matches a string that contains ONLY alphabetic characters (no digits, spaces, or special characters)?

Q.94Medium

What does the `?` quantifier mean when used in a regular expression like `colou?r`?

Q.95Medium

What will the following code output? ```python import re text = 'cat bat sat' result = re.findall(r'[cbr]at', text) print(result) ```

Q.96Medium

What is the purpose of using a raw string (prefix `r`) for regular expression patterns in Python, such as `r'\d+'`?

Q.97Medium

What is the time complexity of accessing an element by index in a Python list?

Q.98Medium

What will be the output of the following code? ```python d = {'a': 1, 'b': 2, 'c': 3} print(list(d.keys())) print(list(d.values())) ```

Q.99Medium

Which of the following Python data structures does NOT allow duplicate elements?

Q.100Medium

What will be the output of the following code? ```python stack = [] stack.append(10) stack.append(20) stack.append(30) stack.pop() print(stack) ```