| Snaprecruit.com

| Snaprecruit.com

Interview question based on skill :

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Which of the following creates a pattern object?

Correct Answer is : re.compile(str)

2. What does the function re.match do?

Correct Answer is : matches a pattern at the start of the string

3. What does the function re.search do?

Correct Answer is : matches a pattern at any position in the string

4. What is the output of the following? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.groups())

Correct Answer is : (‘we’, ‘are’, ‘humans’)

5. What is the output of the following? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.group())

Correct Answer is : ‘we are humans’

6. What is the output of the following? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.group(2))

Correct Answer is : ‘humans’

7. What is the output of the following? sentence = 'horses are fast' regex = re.compile('(?P\w+) (?P\w+) (?P\w+)') matched = re.search(regex, sentence) print(matched.groupdict())

Correct Answer is : {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}

8. What is the output of the following? sentence = 'horses are fast' regex = re.compile('(?P\w+) (?P\w+) (?P\w+)') matched = re.search(regex, sentence) print(matched.groups())

Correct Answer is : (‘horses’, ‘are’, ‘fast’)

9. What is the output of the following? sentence = 'horses are fast' regex = re.compile('(?P\w+) (?P\w+) (?P\w+)') matched = re.search(regex, sentence) print(matched.group(2))

Correct Answer is : ‘are’

10. The character Dot (that is, ‘.’) in the default mode, matches any character other than _____________

Correct Answer is : newline

11. The expression a{5} will match _____________ characters with the previous regular expression.

Correct Answer is : exactly 5

12. ________ matches the start of the string. ________ matches the end of the string.

Correct Answer is : ‘^’, ‘$’

13. Which of the following will result in an error?

Correct Answer is : >>> p = re.subn()

14. What is the output of the line of code shown below? re.split('\W+', 'Hello, hello, hello.')

Correct Answer is : [‘Hello’, ‘hello’, ‘hello’, ”]

15. What is the output of the following function? re.findall("hello world", "hello", 1)

Correct Answer is : [ ]

16. Choose the function whose output can be: <_sre.SRE_Match object; span=(4, 8), match='aaaa'>.

Correct Answer is : >>> re.search(‘aaaa’, “alohaaaa”, 0)

17. Which of the following functions clears the regular expression cache?

Correct Answer is : re.purge()

18. What is the output of the code shown? import re re.ASCII

Correct Answer is : 256

19. Which of the following functions results in case insensitive matching?

Correct Answer is : re.I

20. What is the output of the code shown? re.compile('hello', re.X)

Correct Answer is : re.compile(‘hello’, re.VERBOSE)