MCQs Practice Portal - thefunword.com

Python MCQ Quiz Hub

Python Mcq Set 17

Choose a topic to test your knowledge and improve your Python skills

The process of pickling in Python includes:





✅ Correct Answer: 3

To sterilize an object hierarchy, the _____________ function must be called. To desterilize a data stream, the ______________ function must be called.





✅ Correct Answer: 4

Pick the correct statement regarding pickle and marshal modules.





✅ Correct Answer: 2

What will be the output of the following Python code? pickle.HIGHEST_PROTOCOL





✅ Correct Answer: 1

Which of the following Python codes will result in an error? object = ‘a’





✅ Correct Answer: 3

Which of the following functions can be used to find the protocol version of the pickle module currently being used?





✅ Correct Answer: 4

Which of the following functions can accept more than one positional argument?





✅ Correct Answer: 1

Which of the following functions raises an error when an unpicklable object is encountered by Pickler?





✅ Correct Answer: 2

The pickle module defines ______ exceptions and exports _______ classes.





✅ Correct Answer: 3

Which of the following cannot be pickled?





✅ Correct Answer: 1

If __getstate__() returns _______________ the __setstate__() module will not be called on pickling.





✅ Correct Answer: 2

Lambda functions cannot be pickled because:





✅ Correct Answer: 4

The module _____ is a comparatively faster implementation of the pickle module.





✅ Correct Answer: 1

The copy module uses the ________ protocol for shallow and deep copy.





✅ Correct Answer: 1

Which module in Python supports regular expressions?





✅ Correct Answer: 1

Which of the following creates a pattern object?





✅ Correct Answer: 3

What does the function re.match do?





✅ Correct Answer: 1

What does the function re.search do?





✅ Correct Answer: 2

What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.groups())





✅ Correct Answer: 1

What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.group())





✅ Correct Answer: 4

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





✅ Correct Answer: 3

What will be the output of the following Python code? sentence = 'horses are fast' regex = re.compile('(?P<animal>w+) (?P<verb>w+) (?P<adjective>w+)') matched = re.search(regex, sentence) print(matched.groupdict())





✅ Correct Answer: 1

What will be the output of the following Python code? sentence = 'horses are fast' regex = re.compile('(?P<animal>w+) (?P<verb>w+) (?P<adjective>w+)') matched = re.search(regex, sentence) print(matched.groups())





✅ Correct Answer: 2

What will be the output of the following Python code? sentence = 'horses are fast' regex = re.compile('(?P<animal>w+) (?P<verb>w+) (?P<adjective>w+)') matched = re.search(regex, sentence) print(matched.group(2))





✅ Correct Answer: 4

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





✅ Correct Answer: 4

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





✅ Correct Answer: 2

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





✅ Correct Answer: 1

What will be the output of the following Python code? re.split('W+', 'Hello, hello, hello.')





✅ Correct Answer: 4

What will be the output of the following Python function? re.findall("hello world", "hello", 1)





✅ Correct Answer: 2

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





✅ Correct Answer: 1

Which of the following functions clears the regular expression cache?





✅ Correct Answer: 3

What will be the output of the following Python code? import re re.ASCII





✅ Correct Answer: 4

Which of the following functions results in case insensitive matching?





✅ Correct Answer: 3

What will be the output of the following Python code? re.compile('hello', re.X)





✅ Correct Answer: 2

What will be the output of the following Python code? re.split('[a-c]', '0a3B6', re.I)





✅ Correct Answer: 3

What will be the output of the following Python code? re.sub('morning', 'evening', 'good morning')





✅ Correct Answer: 1

What will be the output of the following Python code? re.escape('new**world')





✅ Correct Answer: 2

What will be the output of the following Python code? re.fullmatch('hello', 'hello world')





✅ Correct Answer: 1

The difference between the functions re.sub and re.subn is that re.sub returns a _______ whereas re.subn returns a ______





✅ Correct Answer: 3

What will be the output of the following Python code? re.split('mum', 'mumbai*', 1)





✅ Correct Answer: 2

What will be the output of the following Python code? re.split(r'(nd)=', 'n1=3.1, n2=5, n3=4.565')





✅ Correct Answer: 2

The function of re.search is ____





✅ Correct Answer: 3

Which of the following functions creates a Python object?





✅ Correct Answer: 1

Which of the following pattern matching modifiers permits whitespace and comments inside the regular expression?





✅ Correct Answer: 4

What will be the output of the following Python code? s = 'welcome home' m = re.match(r'(.*)(.*?)', s) print(m.group())





✅ Correct Answer: 3

The function of re.match is _______





✅ Correct Answer: 4

The special character B matches the empty string, but only when it is ____





✅ Correct Answer: 2

Which of the following special characters matches a pattern only at the end of the string?





✅ Correct Answer: 3

What will be the output of the following Python code? re.match('sp(.*)am', 'spam')





✅ Correct Answer: 2

Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignores)?





✅ Correct Answer: 4