No Result
View All Result
Sunday, September 24, 2023
  • Login
Getting Placed
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship
No Result
View All Result
Getting Placed
No Result
View All Result

Python MCQ’s on Regular Expressions: Set 2

Abhishek by Abhishek
April 28, 2021
in Python
0
python

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

a) caret

b) ampersand

c) percentage symbol

d) newline

Check Answer

Answer: d
The character Dot (that is, ‘,’) in the default mode, matches any character other than newline. If DOTALL flag is used, then it matches any character other than newline.

 

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

a) 5 or less

b) exactly 5

c) 5 or more

d) exactly 4

Check Answer

Answer: b
The character {m} is used to match exactly m characters to the previous regular expression. Hence the expression a{5} will match exactly 5 characters and not less than that.

 

13. ________ matches the start of the string.

________ matches the end of the string.

a) ‘^’, ‘$’

b) ‘$’, ‘^’

c) ‘$’, ‘?’

d) ‘?’, ‘^’

Check Answer

Answer: a
‘^’ (carat) matches the start of the string.
‘$’ (dollar sign) matches the end of the string.

 

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

a)

>>> p = re.compile(“d”)

>>> p.search(“door”)

b) >>> p = re.escape(‘hello’)

c) >>> p = re.subn()

d) >>> p = re.purge()

Check Answer

Answer: c
The function re.subn() will result in an error. This is because subn() requires 3 positional arguments while we have entered none.

 

15. What will be the output of the following Python code?

re.split(‘\W+’, ‘Hello, hello, hello.’)

a) [‘Hello’, ‘hello’, ‘hello.’]

b) [‘Hello, ‘hello’, ‘hello’]

c) [‘Hello’, ‘hello’, ‘hello’, ‘.’]

d) [‘Hello’, ‘hello’, ‘hello’, ”]

Check Answer

Answer: d
In the code shown above, the function split() splits the string based on the pattern given as an argument in the parenthesis. Note: split will never split a string on an empty pattern match. Hence the output of this code is: [‘Hello’, ‘hello’, ‘hello’, ”].

 

16. What will be the output of the following Python function?

re.findall(“hello world”, “hello”, 1)

a) [“hello”]

b) [ ]

c) hello

d) hello world

Check Answer

Answer: b
The function findall returns the word matched if and only if both the pattern and the string match completely, that is, they are exactly the same. Observe the example shown below:
>>> re.findall(“hello”, “hello”, 1) The output is: [‘hello’] Hence the output of the code shown in this question is [].

 

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

a) >>> re.search(‘aaaa’, “alohaaaa”, 0)

b) >>> re.match(‘aaaa’, “alohaaaa”, 0)

c) >>> re.match(‘aaa’, “alohaaa”, 0)

d) >>> re.search(‘aaa’, “alohaaa”, 0)

Check Answer

Answer: a
The output shown above is that of a search function, whose pattern is ‘aaaa’ and the string is that of 8 characters. The only option which matches all these criteria is:
>>> re.search(‘aaaa’, “alohaaaa”, 0)

 

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

a) re.sub()

b) re.pos()

c) re.purge()

d) re.subn()

Check Answer

Answer: c
The function which clears the regular expression cache is re.purge(). Note that this function takes zero positional arguments.

 

19. What will be the output of the following Python code?

import re

re.ASCII

a) 8

b) 32

c) 64

d) 256

Check Answer

Answer: d
The expression re.ASCII returns the total number of ASCII characters that are present, that is 256. This can also be abbreviated as re.A, which results in the same output (that is, 256).

 

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

a) re.A

b) re.U

c) re.I

d) re.X

Check Answer

Answer: c
The function re.I (that is, re.IGNORECASE) results in case-insensitive matching. That is, expressions such as [A-Z] will match lowercase characters too.

 

Page  1  2  3  4  5  6

Python Interview Questions (MCQs)

We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.

Python MCQs on Variables and Operators Python MCQs on Precedence and Associativity
Python MCQs on Data Type Python MCQs on Boolean
Python MCQs on Bitwise Operators Python MCQs on Formatting and Advance Formatting
Python MCQs on Decorators Python MCQs on While and For Loops
Python MCQs on List Python MCQs on List Comprehension
Python MCQs on String Python MCQs on Tuple
Python MCQs on SET Python MCQs on Dictionary
Python MCQs on Functions Python MCQs on Argument Parsing
Python MCQs on Global and Local Variables Python MCQs on Recursion
Python MCQs on Mapping Functions Python MCQs on Modules
Python MCQs on Regular Expressions Python MCQs on Files
Python MCQs on Overloading Python MCQs on Classes and Objects
Python MCQs on Inheritance Python MCQs on Polymorphism and Encapsulation
Python MCQs on Exception Handling
Previous Post

Python MCQ’s on Files: Set 5

Next Post

Python MCQ’s on Regular Expressions: Set 3

Abhishek

Abhishek

Next Post
python

Python MCQ's on Regular Expressions: Set 3

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us on Google News
No Result
View All Result

Recent Posts

  • Mustard Oil Price: सस्ता हुआ सरसों का तेल, खरीदने वालों की लगी भीड़
  • Bhojpuri Video: पवन सिंह ने रात के अंधेरे में मोनालिसा के बदन पर फेरा हाथ, मच गया बवाल
  • Gori Nagori ने उछल-उछल कर तोड़ दिया स्टेज, लगाए ताबड़तोड़ ठुमके
  • Haryanvi Dance: भरी जवानी में Gori Nagori के लगाए लटके-झटकें, देख बूढ़ों में आया जोश
  • Gori Nagori ने स्टेज पर उछल उछल कर लगाए जोरदार ठुमके, वायरल हुआ वीडियो

Recent Comments

  • Abhishek on Win 11 Download Links

Archives

  • September 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • August 2022
  • July 2022
  • October 2021
  • July 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • April 2020
  • February 2020

Categories

  • Admit Card
  • Algorithm and Programs
  • Exam
  • Internship
  • Java
  • Jobs
  • latest
  • politics and entertainment
  • Python
  • Result
  • Trademark
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
  • Privacy Policy
  • DMCA
  • Terms of Use
  • Sitemap

© 2020 Getting Placed

No Result
View All Result
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship

© 2020 Getting Placed

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In