Home » Python MCQ Answers

Python MCQ Answers

Python MCQ Answers. Get all of the validated answers for the python mcq. Ideal for quick and fast review or getting ready for the actual test. if you have short time then you are on right place.

Python MCQ Answers

This is the python mcq with 100% correct answers:

Q1. The process of pickling in Python includes ____________

  1. conversion of a datatable into a list
  2. conversion of a byte stream into Python object hierarchy
  3. conversion of a list into a datatable

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

def foo():
    try:
        return 1
    finally:
        return 2
k = foo()
print(k)
  1. error, there is more than one return statement in a single try-finally block
  2. 3
  3. 1

Q3. Is Python case sensitive when dealing with identifiers?

  1. no
  2. machine dependent
  3. none of the mentioned

Q4. Which of the following is the correct extension of the Python file?

  1. .python
  2. .pl
  3. .p

Q5. Is Python code compiled or interpreted?

  1. Python code is neither compiled nor interpreted
  2. Python code is only compiled
  3. Python code is only interpreted

Q6. All keywords in Python are in _________

  1. Capitalized
  2. lower case
  3. UPPER CASE

Q7. What will be the value of the following Python expression?

print(4 + 3 % 5)
  1. 2
  2. 4
  3. 1

Q8. Which of the following is used to define a block of code in Python language?

  1. Key
  2. Brackets
  3. All of the mentioned

Q9. Which keyword is used for function in Python language?

  1. Function
  2. Fun
  3. Define

Q10. Which of the following character is used to give single-line comments in Python?

  1. //
  2. !
  3. /*

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

i = 1
while True:
    if i%3 == 0:
        break
    print(i)
 
    i + = 1
  1. 1 2 3
  2. 1 2
  3. none of the mentioned

Q12. Which of the following functions can help us to find the version of python that we are currently working on?

  1. sys.version(1)
  2. sys.version(0)
  3. sys.version()

Q13. Python supports the creation of anonymous functions at runtime, using a construct called __________

  1. pi
  2. anonymous
  3. none of the mentioned

Q14. What is the order of precedence in python?

  1. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
  2. Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
  3. Parentheses, Exponential, Multiplication, Addition, Division, Subtraction

Q15. What will be the output of the following Python code snippet if x=1?

x<<2
  1. 2
  2. 1
  3. 8

Q16. What does pip stand for python?

  1. Pip Installs Python
  2. Pip Installs Packages
  3. All of the mentioned

Q17. Which of the following is true for variable names in Python?

  1. underscore and ampersand are the only two special characters allowed
  2. all private members must have leading and trailing underscores
  3. none of the mentioned

Q18. What are the values of the following Python expressions?

print(2**(3**2))
print((2**3)**2)
print(2**3**2)
  1. 512, 512, 512
  2. 64, 512, 64
  3. 64, 64, 64

Q19. Which of the following is the truncation division operator in Python?

  1. |
  2. /
  3. %

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

l=[1, 0, 2, 0, 'hello', '', []]
print(list(filter(bool, l)))
  1. [1, 0, 2, ‘hello’, ”, []]
  2. Error
  3. [1, 0, 2, 0, ‘hello’, ”, []]

Q21. Which of the following functions is a built-in function in python?

  1. factorial()
  2. seed()
  3. sqrt()

Q22. Which of the following is the use of id() function in python?

  1. Every object doesn’t have a unique id
  2. All of the mentioned
  3. None of the mentioned

Q23. The following python program can work with ____ parameters.

def f(x):
    def f1(*args, **kwargs):
           print("Sanfoundry")
           return x(*args, **kwargs)
    return f1
  1. 0
  2. 1
  3. 2

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

print(min(max(False,-3,-4), 2,7))
  1. -4
  2. -3
  3. 2

Q25. Which of the following is not a core data type in Python programming?

  1. Tuples
  2. Lists
  3. Dictionary

Q26. What will be the output of the following Python expression if x=56.236?

print("%.2f"%x)
  1. 56.236
  2. 56.23
  3. 56.0000

Q27. Which of these is the definition for packages in Python?

  1. A set of main modules
  2. A number of files containing Python definitions and statements
  3. A set of programs making use of Python modules

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

print(len(["hello",2, 4, 6]))
  1. Error
  2. 6
  3. 3

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

x = 'abcd'
for i in x:
    print(i.upper())

a.

a
B
C
D

b. a b c d

c. error

d.

A
B
C
D

Q30. What is the order of namespaces in which Python looks for an identifier?

  1. Python first searches the built-in namespace, then the global namespace and finally the local namespace
  2. Python first searches the built-in namespace, then the local namespace and finally the global namespace
  3. Python first searches the global namespace, then the local namespace and finally the built-in namespace

Q31. What will be the output of the following Python code snippet?

for i in [1, 2, 3, 4][::-1]:
    print(i, end=' ')
  1. error
  2. 1 2 3 4
  3. none of the mentioned

Q32. What will be the output of the following Python statement?

print("a"+"bc")
  1. bc
  2. a
  3. bca

Q33. Which function is called when the following Python program is executed?

f = foo()
format(f)
  1. str()
  2. format()
  3. __str__()

Q34. Which one of the following is not a keyword in Python language?

  1. pass
  2. assert
  3. nonlocal

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

class tester:
    def __init__(self, id):
        self.id = str(id)
        id="224"
 
temp = tester(12)
print(temp.id)
  1. 224
  2. None
  3. Error

Q36. What will be the output of the following Python program?

def foo(x):
    x[0] = ['def']
    x[1] = ['abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
  1. Error
  2. None
  3. False

Q37. Which module in the python standard library parses options received from the command line?

  1. getarg
  2. main
  3. os

Q38. What will be the output of the following Python program?

z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
print(z)
  1. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
  2. {‘abc’, ‘p’, ‘q’, ‘san’}
  3. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}

Q39. What arithmetic operators cannot be used with strings in Python?

  1. *
  2. +
  3. All of the mentioned

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

print("abc. DEF".capitalize())
  1. abc. def
  2. Abc. Def
  3. ABC. DEF

Q41. Which of the following statements is used to create an empty set in Python?

  1. ( )
  2. [ ]
  3. { }

Q42. What will be the value of ‘result’ in following Python program?

list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
result.extend(i for i in list1 if i not in (list2+list3) and i not in result)
result.extend(i for i in list2 if i not in (list1+list3) and i not in result)
result.extend(i for i in list3 if i not in (list1+list2) and i not in result)
print(result)
  1. [1, 7, 8]
  2. [1, 2, 4, 7, 8]
  3. error

Q43. To add a new element to a list we use which Python command?

  1. list1.addEnd(5)
  2. list1.addLast(5)
  3. list1.add(5)

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

print('*', "abcde".center(6), '*', sep='')
  1. *  abcde *
  2. * abcde*
  3. * abcde  *

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

list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)
  1. [1, 4]
  2. [1, 3, 4]
  3. [1, 3]

Q46. Which one of the following is the use of function in python?

  1. Functions don’t provide better modularity for your application
  2. you can’t also create your own functions
  3. All of the mentioned

Q47. Which of the following Python statements will result in the output: 6?

A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
  1. A[2][1]
  2. A[3][2]
  3. A[2][3]

Q48. What is the maximum possible length of an identifier in Python?

  1. 79 characters
  2. 31 characters
  3. 63 characters

Q49. What will be the output of the following Python program?

i = 0
while i < 5:
    print(i)
    i += 1
    if i == 3:
        break
else:
    print(0)

a. error

b.

0
1
2
3
0
0
1
2

d. none of the mentioned

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

x = 'abcd'
for i in range(len(x)):
    print(i)
  1. error
  2. 1 2 3 4
  3. a b c d

Q51. What are the two main types of functions in Python?

  1. System function
  2. Custom function
  3. User function

Q52. What will be the output of the following Python program?

def addItem(listParam):
    listParam += [1]
 
mylist = [1, 2, 3, 4]
addItem(mylist)
print(len(mylist))
  1. 8
  2. 2
  3. 1

Q53. Which of the following is a Python tuple?

  1. {1, 2, 3}
  2. {}
  3. [1, 2, 3]

Q54. What will be the output of the following Python code snippet?

z=set('abc$de')
print('a' in z)
  1. Error
  2. False
  3. No output

Q55. What will be the output of the following Python expression?

print(round(4.576))
  1. 4
  2. 4.6
  3. 4.5

Q56. Which of the following is a feature of Python DocString?

  1. In Python all functions should have a docstring
  2. Docstrings can be accessed by the __doc__ attribute on objects
  3. It provides a convenient way of associating documentation with Python modules, functions, classes, and methods

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

print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))
  1. Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)
  2. Error
  3. None of the mentioned

Q58. What is output of print(math.pow(3, 2))?

  1. None
  2. 9
  3. None of the mentioned

Q59. Which of the following is the use of id() function in python?

  1. Every object in Python doesn’t have a unique id
  2. None of the mentioned
  3. All of the mentioned

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

x = [[0], [1]]
print((' '.join(list(map(str, x))),))
  1. 01
  2. [0] [1]
  3. (’01’)

Q61. Who developed Python Programming Language?

  1. Wick van Rossum
  2. Rasmus Lerdorf
  3. Niene Stom

Q62. Which type of Programming does Python support?

  1. object-oriented programming
  2. structured programming
  3. functional programming

Also Read: Cloud Computing MCQ Answers

Note: If you have the new question on this test, please comment Question and Multiple-Choice list in form below this article. We will update answers for you in the shortest time. Thank you! We truly value your contribution to the website.

Leave a Reply

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