iGET

Python Programming - MCQ Practice Questions

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

189 questions | 100% Free

Q.1Medium

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

Q.2Medium

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

Q.3Medium

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

Q.4Medium

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

Q.5Medium

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

Q.6Medium

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

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

Q.8Medium

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

Q.9Medium

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

Q.10Medium

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