Python 3 MCQ (SET-12) – Multiple Choice Questions and Answers

  1. What will be the output after the following statements?
    x = {‘year’: 2016, ‘month’: ‘March’}
    x.setdefault(‘day’, ‘Tuesday’)
    x.setdefault(‘day’, ‘Monday’)
    print(x)
    a. (‘day’, ‘Monday’)
    b. {‘day’: ‘Monday’, ‘month’: ‘March’}
    c. {‘day’: ‘Tuesday’, ‘month’: ‘March’, ‘year’: 2016}
    d. {‘day’: ‘Monday’, ‘month’: ‘March’, ‘year’: 2016}
  2. What will be the data type of x after the following statement?
    x = {}
    a. Tuple
    b. Set
    c. List
    d. Dictionary
  3. What will be the output after the following statement?
    print(r’Today is a \n nice day’)
    a. Today is a \n nice day
    b. Today is a
    nice day
    c. Today is a nice day
    d. ‘Today is a \n nice day’
  4. What will be the output after the following statements?
    x = ‘python jobs’
    x.upper()
    print(x)
    a. PYTHON JOBS
    b. Python jobs
    c. Python Jobs
    d. python jobs
  5. What will be the output after the following statements?
    x = ‘Python Jobs’
    x.lower()
    print(x)
    a. PYTHON JOBS
    b. Python jobs
    c. Python Jobs
    d. python jobs
  6. What will be the output after the following statements?
    x = ‘Python Jobs’
    if x.lower() == ‘python jobs’:
    print(‘Python jobs’)
    else:
    print(‘python 3 jobs’)
    a. python 3 jobs
    b. Python jobs
    c. Python Jobs
    d. python jobs
  7. What will be the output after the following statements?
    x = ‘Python Jobs’
    if x.isupper():
    print(‘Python jobs’)
    else:
    print(‘python 3 jobs’)
    a. python 3 jobs
    b. Python jobs
    c. Python Jobs
    d. python jobs
  8. What will be the output after the following statements?
    x = ‘Python Jobs’
    y = x.upper().lower().upper()
    print(y)
    a. python Jobs
    b. PYTHON JOBS
    c. Python Jobs
    d. python jobs
  9. What will be the output after the following statements?
    x = ‘Python Jobs’
    y = x.upper().lower().isupper()
    print(y)
    a. python jobs
    b. PYTHON JOBS
    c. False
    d. True
  10. What will be the output after the following statements?
    x = [‘Python’, ‘is’, ‘interesting’]
    y = ‘ ‘.join(x)
    print(y)
    a. ‘Python’, ‘is’, ‘interesting’
    b. Python is interesting
    c. Pythonisinteresting
    d. [‘Python’, ‘is’, ‘interesting’]
  11. What will be the output after the following statements?
    x = ‘Python is interesting’
    y = x.split()
    print(y)
    a. ‘Python’, ‘is’, ‘interesting’
    b. Python is interesting
    c. Pythonisinteresting
    d. [‘Python’, ‘is’, ‘interesting’]
  12. What will be the output after the following statements?
    x = ”’Today is a nice day.
    Let’s go for a walk.
    We’ll also go to the park.”’
    y = x.split(‘\n’)
    print(y)
    a. [‘Today is a nice day.’, “Let’s go for a walk.”, “We’ll also go to the park.”]
    b. Today is a nice day.
    c. Let’s go for a walk.
    d. We’ll also go to the park.
  13. What will be the output after the following statements?
    x = ‘Python 2 and Python 3’
    print(x.strip(‘and’))
    a. Python 2
    b. Python 3
    c. Python 2 and Python 3
    d. Python 2 Python 3
  14. What will be the output after the following statements?
    x = ‘Python 2 and Python 3’
    print(x.strip(‘thon 3’))
    a. Python 2
    b. Python 2 and Py
    c. Python 2 and Python 3
    d. Python 2 Python 3
  15. What is the first line of the following statements on Windows?
    #! python3
    x = ‘Python 3’
    a. A comment
    b. Python String
    c. Shebang line
    d. Python Variable
  16. What will be the output after the following statements?
    import re
    x = re.compile(r’\d\d\d-\d\d\d\d’)
    y = x.search(‘The phone number is 444-4444’)
    print(y.group())
    a. The phone number is 444-4444
    b. \d\d\d-\d\d\d\d
    c. 444-4444
    d. r’\d\d\d-\d\d\d\d’
  17. What will be the output after the following statements?
    import re
    x = re.compile(r'(\d\d\d)-(\d\d\d\d)’)
    y = x.search(‘The phone number is 444-4444’)
    print(y.group(2))
    a. The phone number is 444-4444
    b. 4444
    c. 444-4444
    d. 444
  18. What will be the output after the following statements?
    import re
    x = re.compile(r'(\d\d\d)-(\d\d\d\d)’)
    y = x.search(‘The phone number is 444-4444’)
    print(y.group(1))
    a. The phone number is 444-4444
    b. 4444
    c. 444-4444
    d. 444
  19. What will be the output after the following statements?
    import re
    x = re.compile(r'(\d\d\d)-(\d\d\d\d)’)
    y = x.search(‘The phone number is 444-4444’)
    print(y.group(0))
    a. The phone number is 444-4444
    b. 4444
    c. 444-4444
    d. 444
  20. What will be the output after the following statements?
    import re
    x = re.compile(r'(\d\d\d)-(\d\d\d\d)’)
    y = x.search(‘The phone number is 444-4444’)
    print(y.groups())
    a. (‘444’, ‘4444’)
    b. 4444
    c. 444-4444
    d. 444
  21. What will be the output after the following statements?
    import re
    x = re.compile(r'(\(\d\d\d\))-(\d\d\d\d)’)
    y = x.search(‘The phone number is (444)-4444’)
    print(y.group(1))
    a. (‘444’, ‘4444’)
    b. 444
    c. 444-4444
    d. (444)
  22. What will be the output after the following statements?
    import re
    x = re.compile(r’Python 2|Python 3′)
    y = x.search(‘Python 3 MCQ’)
    print(y.group())
    a. Python 2|Python 3
    b. Python 2
    c. Python 3
    d. Python 3 MCQ
  23. What will be the output after the following statements?
    import re
    x = re.compile(r’Python 2|Python 3′)
    y = x.search(‘Python 2.7’)
    print(y.group())
    a. Python 2.7
    b. Python 2
    c. Python 3
    d. Python 2|Python 3
  24. What will be the output after the following statements?
    import re
    x = re.compile(r’day’)
    y = x.search(‘Today is a nice day and a Sunday’)
    print(y.group())
    a. day
    b. Today
    c. nice day
    d. Sunday
  25. What will be the output after the following statements?
    import re
    x = re.compile(r'(Sun)?day’)
    y = x.search(‘Today is a nice day and a Sunday’)
    print(y.group())
    a. day
    b. Today
    c. nice day
    d. Sunday
  26. What will be the output after the following statements?
    import re
    x = re.compile(r'(Sun|To)?day’)
    y = x.search(‘Today is a nice day and a Sunday’)
    print(y.group())
    a. day
    b. Today
    c. nice day
    d. Sunday
  27. What will be the output after the following statements?
    import re
    x = re.compile(r'(Sun)*day’)
    y = x.search(‘Today is a nice day and a Sunday’)
    print(y.group())
    a. nice day
    b. Today
    c. day
    d. Sunday
  28. What will be the output after the following statements?
    import re
    x = re.compile(r'(Sun)+day’)
    y = x.search(‘Today is a nice day and a Sunday’)
    print(y.group())
    a. day
    b. Today
    c. nice day
    d. Sunday
  29. What will be the output after the following statements?
    import re
    x = re.compile(r'(Python){2}’)
    y = x.search(‘PythonPythonPython’)
    print(y.group())
    a. PythonPythonPython
    b. PythonPython
    c. Python
    d. Python 2
  30. What will be the output after the following statements?
    import re
    x = re.compile(r'(Python){2,3}’)
    y = x.search(‘PythonPythonPython’)
    print(y.group())
    a. PythonPythonPython
    b. PythonPython
    c. Python
    d. Python 2
  31. What will be the output after the following statements?
    import re
    x = re.compile(r'(Python){1,3}?’)
    y = x.search(‘PythonPythonPython’)
    print(y.group())
    a. PythonPythonPython
    b. PythonPython
    c. Python
    d. Python 2
  32. What will be the output after the following statements?
    import re
    x = re.compile(r’day’)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. day
    b. Today
    c. [‘day’, ‘day’, ‘day’]
    d. (‘day’, ‘day’, ‘day’)
  33. What will be the output after the following statements?
    import re
    x = re.compile(r'(Sun)?day’)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. (‘day’, ‘day’, ‘day’)
    b. [”, ”, ‘Sun’]
    c. [‘day’, ‘day’, ‘day’]
    d. Sunday
  34. What will be the output after the following statements?
    import re
    x = re.compile(r'(Sun|To)?day’)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. (‘day’, ‘day’, ‘day’)
    b. [”, ”, ‘Sun’]
    c. [‘day’, ‘day’, ‘day’]
    d. [‘To’, ”, ‘Sun’]
  35. What will be the output after the following statements?
    import re
    x = re.compile(r'(Sun)*day’)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. (‘day’, ‘day’, ‘day’)
    b. [”, ”, ‘Sun’]
    c. [‘day’, ‘day’, ‘day’]
    d. [‘To’, ”, ‘Sun’]
  36. What will be the output after the following statements?
    import re
    x = re.compile(r'(Sun)+day’)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. [”, ”, ‘Sun’]
    b. [‘Sun’]
    c. [‘day’, ‘day’, ‘day’]
    d. [‘To’, ”, ‘Sun’]
  37. What will be the output after the following statements?
    import re
    x = re.compile(r'(\(\d\d\d\))-(\d\d\d\d)’)
    y = x.findall(‘The phone number is (444)-4444’)
    print(y)
    a. [(‘(444)’, ‘4444’)]
    b. [(‘444)’, ‘4444’]
    c. ((‘(444)’, ‘4444’))
    d. (‘444’, ‘4444’)
  38. What will be the output after the following statements?
    import re
    x = re.compile(r’\d’)
    y = x.findall(‘The phone number is (444)-4444’)
    print(y)
    a. [(‘(444)’, ‘4444’)]
    b. ‘4’, ‘4’, ‘4’, ‘4’, ‘4’, ‘4’, ‘4’
    c. ((‘(444)’, ‘4444’))
    d. [‘4’, ‘4’, ‘4’, ‘4’, ‘4’, ‘4’, ‘4’]
  39. What will be the output after the following statements?
    import re
    x = re.compile(r’\D’)
    y = x.findall(‘Python 3’)
    print(y)
    a. [‘Python’, ‘3’]
    b. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘ ‘, ‘3’]
    c. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘ ‘]
    d. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]
  40. What will be the output after the following statements?
    import re
    x = re.compile(r’\w’)
    y = x.findall(‘Python_3’)
    print(y)
    a. [‘Python’, ‘3’]
    b. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘3’]
    c. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘ ‘]
    d. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘_’, ‘3’]
  41. What will be the output after the following statements?
    import re
    x = re.compile(r’\W’)
    y = x.findall(‘Python_3’)
    print(y)
    a. [‘Python’, ‘3’]
    b. []
    c. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘ ‘]
    d. [‘ ‘]
  42. What will be the output after the following statements?
    import re
    x = re.compile(r’\s’)
    y = x.findall(‘Python 3’)
    print(y)
    a. [‘Python’, ‘3’]
    b. []
    c. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘ ‘]
    d. [‘ ‘]
  43. What will be the output after the following statements?
    import re
    x = re.compile(r’\S’)
    y = x.findall(‘Python 3’)
    print(y)
    a. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘3’]
    b. []
    c. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘ ‘]
    d. [‘ ‘]
  44. What will be the output after the following statements?
    import re
    x = re.compile(r'[0-9]’)
    y = x.findall(‘Python 3’)
    print(y)
    a. [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’, ‘3’]
    b. []
    c. [‘3’]
    d. [‘ ‘]
  45. What will be the output after the following statements?
    import re
    x = re.compile(r'[ptPT]’)
    y = x.findall(‘Python 3’)
    print(y)
    a. [‘P’, ‘t’, ‘h’, ‘o’, ‘n’]
    b. [‘P’, ‘t’]
    c. []
    d. [‘ ‘]
  46. What will be the output after the following statements?
    import re
    x = re.compile(r'[p-t0-6]’)
    y = x.findall(‘Python 3’)
    print(y)
    a. [‘P’, ‘t’, ‘3’]
    b. [‘P’, ‘t’]
    c. []
    d. [‘t’, ‘3’]
  47. What will be the output after the following statements?
    import re
    x = re.compile(r'[D-S0-2]’)
    y = x.findall(‘Python 3’)
    print(y)
    a. [‘P’, ‘t’, ‘3’]
    b. [‘P’, ‘t’]
    c. [‘P’]
    d. [‘t’, ‘3’]
  48. What will be the output after the following statements?
    import re
    x = re.compile(r'[^A-Za-z0-2]’)
    y = x.findall(‘Python_3’)
    print(y)
    a. [‘_’, ‘3’]
    b. [‘P’, ‘t’]
    c. [‘ ‘, ‘3’]
    d. [‘t’, ‘3’]
  49. What will be the output after the following statements?
    import re
    x = re.compile(r’^Py’)
    y = x.search(‘Python_3’)
    print(y.group())
    a. [‘Py’]
    b. Py
    c. [‘P’, ‘y’]
    d. [‘P’, ‘y’, ‘3’]
  50. What will be the output after the following statements?
    import re
    x = re.compile(r’3$’)
    print(x.search(‘Python_3’) == None)
    a. [‘3’]
    b. Python_3
    c. True
    d. False
  51. What will be the output after the following statements?
    import re
    x = re.compile(r’.day’)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. [‘oday’, ‘nday’]
    b. [‘oday’, ‘ day’, ‘nday’]
    c. [‘day’, ‘day’, ‘day’]
    d. [‘Today’, ‘ day’, ‘Sunday’]
  52. What will be the output after the following statements?
    import re
    x = re.compile(r'(.*)day’)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. [‘To’]
    b. [‘Today is a nice day and a Sunday’]
    c. [‘Today is a nice day and a Sun’]
    d. [‘Today is a nice day’]
  53. What will be the output after the following statements?
    import re
    x = re.compile(r'(.*?)day’)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. [‘To’, ‘ is a nice ‘, ‘ and a Sun’]
    b. [‘Today is a nice day and a Sunday’]
    c. [‘Today is a nice day and a Sun’]
    d. [‘Today is a nice day’]
  54. What will be the output after the following statements?
    import re
    x = re.compile(‘.*’)
    y = x.search(“Today is a nice day.\n Let’s go for a walk.\n We’ll
    also go to the park.”)
    print(y.group())
    a. Today is a nice day.\n Let’s go for a walk.\n We’ll also go to the park.
    b. Today is a nice day.\n Let’s go for a walk.
    c. [‘Today is a nice day.’]
    d. Today is a nice day.
  55. What will be the output after the following statements?
    import re
    x = re.compile(‘.*’, re.DOTALL)
    y = x.search(“Today is a nice day.\n Let’s go for a walk.\n We’ll
    also go to the park.”)
    print(y.group())
    a. Today is a nice day.
    Let’s go for a walk.
    We’ll also go to the park.
    b. Today is a nice day.\n Let’s go for a walk.
    c. [‘Today is a nice day.’]
    d. Today is a nice day.
  56. What will be the output after the following statements?
    import re
    x = re.compile(‘Day’)
    y = x.search(‘Today is a nice day’)
    print(y)
    a. Today is a nice day.
    b. None
    c. [‘Today is a nice day.’]
    d. (Today is a nice day.)
  57. What will be the output after the following statements?
    import re
    x = re.compile(‘Day’, re.I)
    y = x.search(‘Today is a nice day’)
    print(y.group())
    a. Today is a nice day.
    b. None
    c. [‘Today is a nice day.’]
    d. day
  58. What will be the output after the following statements?
    import re
    x = re.compile(‘day’, re.IGNORECASE)
    y = x.findall(‘Today is a nice day and a Sunday’)
    print(y)
    a. [Today is a nice day.]
    b. [‘day’, ‘day’]
    c. [‘day’, ‘day’, ‘day’]
    d. day
  59. What will be the output after the following statements?
    import re
    x = re.compile(‘Sunday’)
    y = x.sub(‘Wednesday’, ‘Today is a nice day and a Sunday’)
    print(y)
    a. Today is a nice day
    b. Today is a nice day and a Sunday
    c. [‘Sunday’]
    d. Today is a nice day and a Wednesday
  60. What will be the output after the following statements?
    import os
    x = os.getcwd()
    print(x)
    a. Name of the operating system
    b. Version of the operating system
    c. The current working directory
    d. Name of the current file
  61. What do the following statements do?
    import webbrowser
    webbrowser.open(‘http://google.com’)
    a. Ping http://google.com
    b. Display http://google.com in the shell
    c. Download http://google.com as a text file
    d. Launch a browser window to http://google.com
  62. What will be the output after the following statements?
    import sys
    print(sys.argv)
    a. A set of the program’s filename and command line arguments
    b. A list of the program’s filename and command line arguments
    c. A tuple of the program’s filename and command line arguments
    d. A dictionary of the program’s filename and command line arguments
SHARE:

Leave a Comment