Python/Python Mcq Set 17 Sample Test,Sample questions

adplus-dvertising

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

1.caret

2.ampersand

3.percentage symbol

4.newline

Posted Date:-2022-01-02 03:13:17


Question:
 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

Posted Date:-2022-01-02 03:35:33


Question:
 The pickle module defines ______ exceptions and exports _______ classes.

1.2, 3

2.3, 4

3.3, 2

4. 4, 3

Posted Date:-2022-01-02 03:01:35


Question:
 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

Posted Date:-2022-01-02 02:56:43


Question:
 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’]

Posted Date:-2022-01-02 03:27:56


Question:
 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’

Posted Date:-2022-01-02 03:09:22


Question:
 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’

Posted Date:-2022-01-02 03:07:46


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

1. Error

2. [”, ‘bai*’]

3. [”, ‘bai’]

4. [‘bai*’]

Posted Date:-2022-01-02 03:31:06


Question:
 What will be the output of the following Python function?

re.findall("hello world", "hello", 1)

1. [“hello”]

2. [ ]

3.hello

4.hello world

Posted Date:-2022-01-02 03:15:15


Question:
 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)

Posted Date:-2022-01-02 03:34:08


Question:
 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

Posted Date:-2022-01-02 03:01:08


Question:
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)

Posted Date:-2022-01-02 03:15:42


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

1.True value

2.False value

3.ValueError

4.OverflowError

Posted Date:-2022-01-02 03:02:33


Question:
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>

Posted Date:-2022-01-02 03:03:01


Question:
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

Posted Date:-2022-01-02 02:58:15


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

1. pickle

2.marshal

3.shelve

4.copyreg

Posted Date:-2022-01-02 03:03:59


Question:
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

Posted Date:-2022-01-02 03:30:25


Question:
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

Posted Date:-2022-01-02 03:13:46


Question:
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

Posted Date:-2022-01-02 03:33:35


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

1.cPickle

2.nPickle

3.gPickle

4.tPickle

Posted Date:-2022-01-02 03:03:26


Question:
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

Posted Date:-2022-01-02 03:36:00


Question:
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()

Posted Date:-2022-01-02 02:57:40


Question:
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

Posted Date:-2022-01-02 03:06:09


Question:
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

Posted Date:-2022-01-02 03:06:38


Question:
What will be the output of the following Python code?

import re
re.ASCII

1.8

2.32

3. 64

4.256

Posted Date:-2022-01-02 03:17:38


Question:
What will be the output of the following Python code?

pickle.HIGHEST_PROTOCOL

1.4

2.5

3.3

4.6

Posted Date:-2022-01-02 02:59:07


Question:
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

Posted Date:-2022-01-02 03:21:16


Question:
What will be the output of the following Python code?

re.escape('new**world')

1. ‘new world’

2. ‘new\*\*world’

3.‘**’

4. ‘new’, ‘*’, ‘*’, ‘world’

Posted Date:-2022-01-02 03:28:58


Question:
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

Posted Date:-2022-01-02 03:29:41


Question:
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

Posted Date:-2022-01-02 03:37:42


Question:
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’, ”]

Posted Date:-2022-01-02 03:14:48


Question:
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’]

Posted Date:-2022-01-02 03:33:05


Question:
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’

Posted Date:-2022-01-02 03:28:21


Question:
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’ ]

Posted Date:-2022-01-02 03:34:59


Question:
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’

Posted Date:-2022-01-02 03:11:56


Question:
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’

Posted Date:-2022-01-02 03:08:46


Question:
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’

Posted Date:-2022-01-02 03:08:17


Question:
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’

Posted Date:-2022-01-02 03:07:19


Question:
Which module in Python supports regular expressions?

1. re

2. regex

3.pyregex

4.none of the mentioned

Posted Date:-2022-01-02 03:05:18


Question:
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

Posted Date:-2022-01-02 03:02:10


Question:
Which of the following creates a pattern object?

1.re.create(str)

2.re.regex(str)

3.re.compile(str)

4.re.assemble(str)

Posted Date:-2022-01-02 03:05:45


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

1.pickle.dumps

2.pickle.loads

3.pickle.dump

4. pickle.load

Posted Date:-2022-01-02 03:00:31


Question:
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

Posted Date:-2022-01-02 03:00:02


Question:
Which of the following functions clears the regular expression cache?

1.re.sub()

2. re.pos()

3.re.purge()

4.re.subn()

Posted Date:-2022-01-02 03:16:56


Question:
Which of the following functions results in case insensitive matching?

1. re.A

2. re.U

3. re.I

4.re.X

Posted Date:-2022-01-02 03:18:00


Question:
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

Posted Date:-2022-01-02 03:34:32


Question:
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)

Posted Date:-2022-01-02 02:59:37


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

1. B

2.X

3.

4.A

Posted Date:-2022-01-02 03:36:29


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

1.(?:…)

2.(?=…)

3.(?!…)

4.(?#…)

Posted Date:-2022-01-02 03:38:26


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

1. ‘^’, ‘$’

2. ‘$’, ‘^’

3. ‘$’, ‘?’

4. ‘?’, ‘^’

Posted Date:-2022-01-02 03:14:13


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!