Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignores)?
Correct Answer is : (?#…)
2. Which of the codes shown below results in a match?
Correct Answer is : re.match(‘George(?=Washington)’, ‘GeorgeWashington’)
3. What is the output of the code shown below?
re.split(r'(a)(t)', 'Maths is a difficult subject')
Correct Answer is : [‘M’, ‘a’, ‘t’, ‘hs is a difficult subject’]
4. The output of the two codes shown below is the same. State whether true or false.
CODE 1
>>> re.split(r'(a)(t)', 'The night sky')
CODE 2
>>> re.split(r'\s+', 'The night sky')
Correct Answer is : FALSE
5. What is the output of the code shown below?
import re
s = 'abc123 xyz666 lmn-11 def77'
re.sub(r'\b([a-z]+)(\d+)', r'\2\1:', s)
Correct Answer is : ‘123abc: 666xyz: lmn-11 77def:’
6. What is the output of the code shown?
re.subn('A', 'X', 'AAAAAA', count=4)
Correct Answer is : (‘XXXXAA’, 4)
7. What is the output of the code shown below?
n = re.sub(r'\w+', 'Hello', 'Cats and dogs')
Correct Answer is : ‘Hello Hello Hello’
8. What is the output of the following code?
w = re.compile('[A-Za-z]+')
w.findall('It will rain today')
Correct Answer is : [‘It’, ‘will’, ‘rain’, ‘today’]
9. In the functions re.search.start(group) and re.search.end(group), if the argument groups not specified, it defaults to __________
Correct Answer is : Zero
10. What is the output of the code shown below?
re.split(r'\s+', 'Chrome is better than explorer', maxspilt=3)
Correct Answer is : [‘Chrome’, ‘is’, ‘better’, ‘than explorer’]
11. What is the output of the code shown below?
a=re.compile('[0-9]+')
a.findall('7 apples and 3 mangoes')
Correct Answer is : [‘7’, ‘4’]
12. Which of the following functions returns a dictionary mapping group names to group numbers?
Correct Answer is : re.compile.groupindex
13. Which of the following statements regarding the output of the function re.match is incorrect?
Correct Answer is : ‘pq+’ matches ‘p’
14. The snippet of code shown below results in an error. State whether true or false.
c=re.compile(r'(\d+)(\[A-Z]+)([a-z]+)')
c.groupindex
Correct Answer is : FALSE
15. Which of the following functions does not accept any argument?
Correct Answer is : re.purge
16. What is the output of the code shown below?
a = re.compile('0-9')
a.findall('3 trees')
Correct Answer is : Error
17. Which of the following lines of code will not show a match?
Correct Answer is : >>> re.match(‘ab*’, ‘ba’)
18. What is the output of the code shown below?
m = re.search('a', 'The blue umbrella')
m.re.pattern
Correct Answer is : ‘a’
19. What is the output of the function shown below?
re.sub('Y', 'X', 'AAAAAA', count=2)