The character Dot (that is, ‘.’) in the default mode, matches any character other than _______
1.caret
2.ampersand
3.percentage symbol
4.newline
The function of re.match is _______
1. Error
2.Matches a pattern anywhere in the string
3.Matches a pattern at the end of the string
4.Matches a pattern at the start of the string
The pickle module defines ______ exceptions and exports _______ classes.
1.2, 3
2.3, 4
3.3, 2
4. 4, 3
The process of pickling in Python includes:
1.conversion of a list into a datatable
2. conversion of a byte stream into Python object hierarchy
3.conversion of a Python object hierarchy into byte stream
4.conversion of a datatable into a list
What will be the output of the following Python code? re.split('[a-c]', '0a3B6', re.I)
1.Error
2. [‘a’, ‘B’]
3. [‘0’, ‘3B6’]
4.[‘a’]
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())
1. {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
2.(‘horses’, ‘are’, ‘fast’)
3. ‘horses are fast’
4. ‘are’
What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.group())
1.(‘we’, ‘are’, ‘humans’)
2.(we, are, humans)
3.(‘we’, ‘humans’)
4.‘we are humans’
What will be the output of the following Python code? re.split('mum', 'mumbai*', 1)
1. Error
2. [â€, ‘bai*’]
3. [â€, ‘bai’]
4. [‘bai*’]
What will be the output of the following Python function? re.findall("hello world", "hello", 1)
1. [“helloâ€]
2. [ ]
3.hello
4.hello world
Which of the following functions creates a Python object?
1.re.compile(str)
2.re.assemble(str)
3.re.regex(str)
4.re.create(str)
Which of the following functions raises an error when an unpicklable object is encountered by Pickler?
1.pickle.PickleError
2.pickle.PicklingError
3.pickle.UnpickleError
4.pickle.UnpicklingError
Choose the function whose output can be: <_sre.SRE_Match object; span=(4, 8), match=’aaaa’>.
1.>>> re.search(‘aaaa’, “alohaaaaâ€, 0)
2.>>> re.match(‘aaaa’, “alohaaaaâ€, 0)
3. >>> re.match(‘aaa’, “alohaaaâ€, 0)
4.>>> re.search(‘aaa’, “alohaaaâ€, 0)
If __getstate__() returns _______________ the __setstate__() module will not be called on pickling.
1.True value
2.False value
3.ValueError
4.OverflowError
Lambda functions cannot be pickled because:
1.Lambda functions only deal with binary values, that is, 0 and 1
2.Lambda functions cannot be called directly
3.Lambda functions cannot be identified by the functions of the pickle module
4. All lambda functions have the same name, that is, <lambda>
Pick the correct statement regarding pickle and marshal modules.
1.The pickle module supports primarily .pyc files whereas marshal module is used to sterilize Python objects
2.The pickle module keeps track of the objects that have already been sterilized whereas the marshal module does not do this
3.The pickle module cannot be used to sterilize user defined classes and their instances whereas marshal module can be used to perform this task
4. The format of sterilization of the pickle module is not guaranteed to be supported across all versions of Python. The marshal module sterilization is compatible across all the versions of Python
The copy module uses the ________ protocol for shallow and deep copy.
1. pickle
2.marshal
3.shelve
4.copyreg
The difference between the functions re.sub and re.subn is that re.sub returns a _______ whereas re.subn returns a ______
1.string, list
2. list, tuple
3. string, tuple
4.tuple, list
The expression a{5} will match _____ characters with the previous regular expression.
1. 5 or less
2.exactly 5
3. 5 or more
4.exactly 4
The function of re.search is ____
1.Matches a pattern at the start of the string
2.Matches a pattern at the end of the string
3.Matches a pattern from any part of a string
4. Such a function does not exist
The module _____ is a comparatively faster implementation of the pickle module.
1.cPickle
2.nPickle
3.gPickle
4.tPickle
The special character B matches the empty string, but only when it is ____
1.at the beginning or end of a word
2.not at the beginning or end of a word
3.at the beginning of the word
4.at the end of the word
To sterilize an object hierarchy, the _____________ function must be called. To desterilize a data stream, the ______________ function must be called.
1.dumps(), undumps()
2.loads(), unloads()
3.loads(), dumps()
4.dumps(), loads()
What does the function re.match do?
1.matches a pattern at the start of the string
2.matches a pattern at any position in the string
3.such a function does not exist
4. None of the mentioned
What does the function re.search do?
1.matches a pattern at the start of the string
2.matches a pattern at any position in the string
3.such a function does not exist
4. None of the mentioned
What will be the output of the following Python code? import re re.ASCII
1.8
2.32
3. 64
4.256
What will be the output of the following Python code? pickle.HIGHEST_PROTOCOL
1.4
2.5
3.3
4.6
What will be the output of the following Python code? re.compile('hello', re.X)
1.[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
2.re.compile(‘hello’, re.VERBOSE)
3. Error
4.Junk value
What will be the output of the following Python code? re.escape('new**world')
1. ‘new world’
2. ‘new\*\*world’
3.‘**’
4. ‘new’, ‘*’, ‘*’, ‘world’
What will be the output of the following Python code? re.fullmatch('hello', 'hello world')
1. No output
2.[]
3.<_sre.SRE_Match object; span=(0, 5), match='hello'>
4. error
What will be the output of the following Python code? re.match('sp(.*)am', 'spam')
1.<_sre.SRE_Match object; span=(1, 4), match=’spam’>
2. <_sre.SRE_Match object; span=(0, 4), match=’spam’>
3.No output
4.Error
What will be the output of the following Python code? re.split('W+', 'Hello, hello, hello.')
1. [‘Hello’, ‘hello’, ‘hello.’]
2.[‘Hello, ‘hello’, ‘hello’]
3.[‘Hello’, ‘hello’, ‘hello’, ‘.’]
4.[‘Hello’, ‘hello’, ‘hello’, â€]
What will be the output of the following Python code? re.split(r'(nd)=', 'n1=3.1, n2=5, n3=4.565')
1.Error
2.[â€, ‘n1’, ‘3.1, ‘, ‘n2’, ‘5, ‘, ‘n3’, ‘4.565’]
3. [‘n1’, ‘3.1, ‘, ‘n2’, ‘5, ‘, ‘n3’, ‘4.565’]
4. [‘3.1, ‘, ‘5, ‘, ‘4.565’]
What will be the output of the following Python code? re.sub('morning', 'evening', 'good morning')
1. ‘good evening’
2. ‘good’
3.‘morning’
4.‘evening’
What will be the output of the following Python code? s = 'welcome home' m = re.match(r'(.*)(.*?)', s) print(m.group())
1.(‘welcome’, ‘home’)
2. [‘welcome’, ‘home’]
3.welcome home
4. [‘welcome’ // ‘home’ ]
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))
1. {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
2.(‘horses’, ‘are’, ‘fast’)
3. ‘horses are fast’
4.‘are’
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())
1. {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
2. (‘horses’, ‘are’, ‘fast’)
3.horses are fast’
4. ‘are’
What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.group(2))
1.‘are’
2.‘we’
3.‘humans’
4.‘we are humans’
What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.groups())
1. (‘we’, ‘are’, ‘humans’)
2. (we, are, humans)
3. (‘we’, ‘humans’)
4.‘we are humans’
Which module in Python supports regular expressions?
1. re
2. regex
3.pyregex
4.none of the mentioned
Which of the following cannot be pickled?
1.Functions which are defined at the top level of a module with lambda
2.Functions which are defined at the top level of a module with def
3. Built-in functions which are defined at the top level of a module
4.Classes which are defined at the top level of a module
Which of the following creates a pattern object?
1.re.create(str)
2.re.regex(str)
3.re.compile(str)
4.re.assemble(str)
Which of the following functions can accept more than one positional argument?
1.pickle.dumps
2.pickle.loads
3.pickle.dump
4. pickle.load
Which of the following functions can be used to find the protocol version of the pickle module currently being used?
1.pickle.DEFAULT
2.pickle.CURRENT
3.pickle.CURRENT_PROTOCOL
4.pickle.DEFAULT_PROTOCOL
Which of the following functions clears the regular expression cache?
1.re.sub()
2. re.pos()
3.re.purge()
4.re.subn()
Which of the following functions results in case insensitive matching?
1. re.A
2. re.U
3. re.I
4.re.X
Which of the following pattern matching modifiers permits whitespace and comments inside the regular expression?
1. re.L
2. re.S
3.re.U
4.re.X
Which of the following Python codes will result in an error? object = ‘a’
1. >>> pickle.dumps(object)
2. >>> pickle.dumps(object, 3)
3.>>> pickle.dumps(object, 3, True)
4.>>> pickle.dumps(‘a’, 2)
Which of the following special characters matches a pattern only at the end of the string?
1. B
2.X
3.
4.A
Which of the following special characters represents a comment (that is, the contents of the parenthesis are simply ignores)?
1.(?:…)
2.(?=…)
3.(?!…)
4.(?#…)
______ matches the start of the string. ________ matches the end of the string.
1. ‘^’, ‘$’
2. ‘$’, ‘^’
3. ‘$’, ‘?’
4. ‘?’, ‘^’