MCQOPTIONS
Saved Bookmarks
This section includes 9 Mcqs, each offering curated multiple-choice questions to sharpen your Python knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Which of the codes shown below results in a match? |
| A. | re.match(‘George(?=Washington)’, ‘George Washington’) |
| B. | re.match(‘George(?=Washington)’, ‘George’) |
| C. | re.match(‘George(?=Washington)’, ‘GeorgeWashington’) |
| D. | re.match(‘George(?=Washington)’, ‘Georgewashington’) |
| Answer» D. re.match(‘George(?=Washington)’, ‘Georgewashington’) | |
| 2. |
Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignores)? |
| A. | (?:…) |
| B. | (?=…) |
| C. | (?!…) |
| D. | (?#…) |
| Answer» E. | |
| 3. |
The output of the following two Python codes are the same. |
| A. | True |
| B. | FalseView Answer |
| Answer» B. FalseView Answer | |
| 4. |
Which of the following special characters matches a pattern only at the end of the string? |
| A. | \B |
| B. | \X |
| C. | \Z |
| D. | \A |
| Answer» D. \A | |
| 5. |
The special character \B matches the empty string, but only when it is _____________ |
| A. | at the beginning or end of a word |
| B. | not at the beginning or end of a word |
| C. | at the beginning of the word |
| D. | at the end of the word |
| Answer» C. at the beginning of the word | |
| 6. |
The function of re.match is ____________ |
| A. | Error |
| B. | Matches a pattern anywhere in the string |
| C. | Matches a pattern at the end of the string |
| D. | Matches a pattern at the start of the string |
| Answer» E. | |
| 7. |
Which of the following pattern matching modifiers permits whitespace and comments inside the regular expression? |
| A. | re.L |
| B. | re.S |
| C. | re.U |
| D. | re.X |
| Answer» E. | |
| 8. |
Which of the following functions creates a Python object? |
| A. | re.compile(str) |
| B. | re.assemble(str) |
| C. | re.regex(str) |
| D. | re.create(str) |
| Answer» B. re.assemble(str) | |
| 9. |
The function of re.search is __________ |
| A. | Matches a pattern at the start of the string |
| B. | Matches a pattern at the end of the string |
| C. | Matches a pattern from any part of a string |
| D. | Such a function does not exist |
| Answer» D. Such a function does not exist | |