iGET

Python Programming - MCQ Practice Questions

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

188 questions | 100% Free

Q.141Medium

Which of the following statements about lambda functions in Python is CORRECT?

Q.142Medium

What will be the output of the following code? def outer(): x = 10 def inner(): nonlocal x x += 5 inner() return x print(outer())

Q.143Medium

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

Q.144Medium

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

Q.145Medium

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

Q.146Medium

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.147Medium

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

Q.148Medium

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.149Medium

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

Q.150Medium

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

Q.151Medium

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

Q.152Medium

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

Q.153Medium

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

Q.154Medium

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.155Medium

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

Q.156Medium

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

Q.157Medium

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

Q.158Medium

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

Q.159Medium

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

Q.160Medium

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())) ```