Saved Bookmarks
| 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» Right option is (c) re.match(‘George(?=Washington)’, ‘GeorgeWashington’) Best explanation: The code shown above demonstrates the use of the function re.match, along with the special character ?=. This results in a match only when ‘George’ is immediately followed by ‘Washington’. Also, we have not used the module to ignore case. Hence the match is case-sensitive. Therefore the only option which results in a match is: re.match(‘George(?=Washington)’, ‘GeorgeWashington’) |
|