0% found this document useful (0 votes)
10 views49 pages

Python MCQ

The document is a Python MCQ Mastery Guide containing 66 multiple-choice questions related to Python programming. Each question includes options and the correct answer, covering topics such as Python's features, syntax, data types, and functions. It serves as a study resource for individuals looking to enhance their knowledge and skills in Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views49 pages

Python MCQ

The document is a Python MCQ Mastery Guide containing 66 multiple-choice questions related to Python programming. Each question includes options and the correct answer, covering topics such as Python's features, syntax, data types, and functions. It serves as a study resource for individuals looking to enhance their knowledge and skills in Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE

PYTHON MCQ
Q1: Who developed Python Programming Language?
A) Wick van Rossum
B) Rasmus Lerdorf
C) Guido van Rossum
D) Niene Stom
Answer: Guido van Rossum
Q2: Which type of Programming does Python support?
A) object-oriented programming
B) structured programming
C) functional programming
D) all of the mentioned
Answer: all of the mentioned
Q3: Is Python case sensitive when dealing with identifiers?
A) no
B) yes
C) machine dependent
D) none of the mentioned
Answer: yes
Q4: Which of the following is the correct extension of the Python file?
A) .python
B) .pl
C) .py
D) .p
Answer: .py
Q5: Is Python code compiled or interpreted?
A) Python code is both compiled and interpreted
B) Python code is neither compiled nor interpreted
C) Python code is only compiled
D) Python code is only interpreted
Answer: Python code is both compiled and interpreted
Q6: All keywords in Python are in _________
A) Capitalized
B) lower case
C) UPPER CASE
D) None of the mentioned
Answer: None of the mentioned
Q7: What will be the value of the following Python expression? 4 + 3 % 5
A) 2
B) 7
C) 4

1|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
D) 1
Answer: 7
Q8: Which of the following is used to define a block of code in Python language?
A) Indentation
B) Key
C) Brackets
D) All of the mentioned
Answer: Indentation
Q9: Which keyword is used for function in Python language?
A) Function
B) def
C) Fun
D) Define
Answer: def
Q10: Which of the following character is used to give single-line comments in Python?
A) //
B) #
C) !
D) /*
Answer: #
Q11: Which of the following functions can help us to find the version of python that we are currently
working on?
A) sys.version(1)
B) sys.version(0)
C) sys.version()
D) sys.version
Answer: sys.version
Q12: Python supports the creation of anonymous functions at runtime, using a construct called
__________
A) pi
B) anonymous
C) lambda
D) none of the mentioned
Answer: lambda
Q13: What is the order of precedence in python?
A) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
B) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
C) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
D) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Answer: Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Q14: What will be the output of the following Python code snippet if x=1? x<<2
A) 4
B) 2

2|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
C) 1
D) 8
Answer: 4
Q15: What does pip stand for python?
A) Pip Installs Python
B) Pip Installs Packages
C) Preferred Installer Program
D) All of the mentioned
Answer: Preferred Installer Program
Q16: Which of the following is true for variable names in Python?
A) underscore and ampersand are the only two special characters allowed
B) unlimited length
C) all private members must have leading and trailing underscores
D) none of the mentioned
Answer: unlimited length
Q17: Which of the following is the truncation division operator in Python?
A) |
B) //
C) /
D) %
Answer: //
Q18: Which of the following functions is a built-in function in python?
A) factorial()
B) print()
C) seed()
D) sqrt()
Answer: print()
Q19: Which of the following is the use of id() function in python?
A) Every object doesn’t have a unique id
B) Id returns the identity of the object
C) All of the mentioned
D) None of the mentioned
Answer: Id returns the identity of the object
Q20: What will be the output of the following Python function? min(max(False,-3,-4), 2,7)
A) -4
B) -3
C) 2
D) False
Answer: False
Q21: Which of the following is not a core data type in Python programming?
A) Tuples
B) Lists
C) Class

3|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
D) Dictionary
Answer: Class
Q22: What will be the output of the following Python expression if x=56.236? print("%.2f"%x)
A) 56.236
B) 56.23
C) 56
D) 56.24
Answer: 56.24
Q23: Which of these is the definition for packages in Python?
A) A set of main modules
B) A folder of python modules
C) A number of files containing Python definitions and statements
D) A set of programs making use of Python modules
Answer: A folder of python modules
Q24: What will be the output of the following Python function? len(["hello",2, 4, 6])
A) Error
B) 6
C) 4
D) 3
Answer: 4
Q25: What is the order of namespaces in which Python looks for an identifier?
A) Python first searches the built-in namespace, then the global namespace and finally the local
namespace
B) Python first searches the built-in namespace, then the local namespace and finally the global
namespace
C) Python first searches the local namespace, then the global namespace and finally the built-in
namespace
D) Python first searches the global namespace, then the local namespace and finally the built-in
namespace
Answer: Python first searches the local namespace, then the global namespace and finally the built-in
namespace
Q26: What will be the output of the following Python statement? >>>"a"+"bc"
A) bc
B) abc
C) a
D) bca
Answer: abc
Q27: Which function is called when the following Python program is executed? f = foo() format(f)
A) str()
B) format()
C) __str__()
D) __format__()
Answer: __str__()

4|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Q28: Which one of the following is not a keyword in Python language?
A) pass
B) eval
C) assert
D) nonlocal
Answer: eval
Q29: Which module in the python standard library parses options received from the command line?
A) getarg
B) getopt
C) main
D) os
Answer: getopt
Q30: What arithmetic operators cannot be used with strings in Python?
A) *
B) –
C) +
D) All of the mentioned
Answer: –
Q31: What will be the output of the following Python code? print("abc. DEF".capitalize())
A) Abc. def
B) abc. def
C) Abc. Def
D) ABC. DEF
Answer: Abc. def
Q32: Which of the following statements is used to create an empty set in Python?
A) ( )
B) [ ]
C) { }
D) set()
Answer: set()
Q33: To add a new element to a list we use which Python command?
A) list1.addEnd(5)
B) list1.addLast(5)
C) list1.append(5)
D) list1.add(5)
Answer: list1.append(5)
Q34: What will be the output of the following Python code? print('*', "abcde".center(6), '*', sep='')
A) * abcde *
B) *abcde *
C) * abcde*
D) * abcde *
Answer: *abcde *
Q35: Which one of the following is the use of function in python?

5|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
A) Functions don’t provide better modularity for your application
B) you can’t also create your own functions
C) Functions are reusable pieces of programs
D) All of the mentioned
Answer: Functions are reusable pieces of programs
Q36: What is the maximum possible length of an identifier in Python?
A) 79 characters
B) 31 characters
C) 63 characters
D) none of the mentioned
Answer: none of the mentioned
Q37: What are the two main types of functions in Python?
A) System function
B) Custom function
C) Built-in function & User defined function
D) User function
Answer: Built-in function & User defined function
Q38: Which of the following is a Python tuple?
A) {1, 2, 3}
B) {}
C) [1, 2, 3]
D) (1, 2, 3)
Answer: (1, 2, 3)
Q39: What will be the output of the following Python code snippet? z=set('abc$de') 'a' in z
A) Error
B) True
C) False
D) No output
Answer: True
Q40: What will be the output of the following Python expression? round(4.576)
A) 4
B) 4.6
C) 5
D) 4.5
Answer: 5
Q41: Which of the following is a feature of Python DocString?
A) In Python all functions should have a docstring
B) Docstrings can be accessed by the __doc__ attribute on objects
C) It provides a convenient way of associating documentation with Python modules, functions, classes,
and methods
D) All of the mentioned
Answer: All of the mentioned

6|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Q42: What will be the output of the following Python code? print("Hello {0[0]} and {0[1]}".format(('foo',
'bin')))
A) Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)
B) Error
C) Hello foo and bin
D) None of the mentioned
Answer: Hello foo and bin
Q43: What is output of print(math.pow(3, 2))?
A) 9
B) None
C) 9
D) None of the mentioned
Answer: 9
Q44: Which of the following is the use of id() function in python?
A) Every object in Python doesn’t have a unique id
B) In Python Id function returns the identity of the object
C) None of the mentioned
D) All of the mentioned
Answer: In Python Id function returns the identity of the object
Q45: What will be the output of the following Python code? x = [[0], [1]] print((' '.join(list(map(str, x))),))
A) 1
B) [0] [1]
C) (’01’)
D) (‘[0] [1]’,)
Answer: (‘[0] [1]’,)
Q46: The process of pickling in Python includes ____________
A) conversion of a Python object hierarchy into byte stream
B) conversion of a datatable into a list
C) conversion of a byte stream into Python object hierarchy
D) conversion of a list into a datatable
Answer: conversion of a Python object hierarchy into byte stream
Q47: What will be the output of the following Python code snippet? ['hello', 'morning'][bool('')]
A) error
B) no output
C) hello
D) morning
Answer: hello
Q48: What will be the output of the following Python code? ['f', 't'][bool('spam')]
A) t
B) f
C) No output
D) Error
Answer: t

7|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Q49: What will be the output of the following Python code? l=[1, 0, 2, 0, 'hello', '', []] list(filter(bool, l))
A) Error
B) [1, 0, 2, 0, ‘hello’, ”, []]
C) [1, 0, 2, ‘hello’, ”, []]
D) [1, 2, ‘hello’]
Answer: [1, 2, ‘hello’]
Q50: Which of the following Boolean expressions is not logically equivalent to the other three?
A) not(-6<0 or-6>10)
B) -6>=0 and -6<=10
C) not(-6<10 or-6==10)
D) not(-6>10 or-6==10)
Answer: not(-6>10 or-6==10)
Q51: What will be the output of the following Python code snippet? not(10<20) and not(10>30)
A) True
B) False
C) Error
D) No output
Answer: False
Q52: What will be the output of the following Python statement? >>>chr(ord('A'))
A) A
B) B
C) a
D) Error
Answer: A
Q53: What will be the output of the following Python statement? >>>print(chr(ord('b')+1))
A) a
B) b
C) c
D) A
Answer: c
Q54: Which of the following statement prints hello\example\test.txt?
A) print(“hello\example\test.txt”)
B) print(“hello\\example\\test.txt”)
C) print(“hello\”example\”test.txt”)
D) print(“hello”\example”\test.txt”)
Answer: print(“hello\\example\\test.txt”)
Q55: Suppose s is “\t\tWorld\n”, what is s.strip()?
A) \t\tWorld\n
B) \t\tWorld\n
C) \t\tWORLD\n
D) World
Answer: World
Q56: The format function, when applied on a string returns ___________

8|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
A) Error
B) int
C) bool
D) str
Answer: str
Q57: What will be the output of the “hello” +1+2+3?
A) hello123
B) hello
C) Error
D) hello6
Answer: Error
Q58: What will be displayed by print(ord(‘b’) – ord(‘a’))?
A) 0
B) 1
C) -1
D) 2
Answer: 1
Q59: Say s=”hello” what will be the return value of type(s)?
A) int
B) bool
C) str
D) String
Answer: str
Q60: What is “Hello”.replace(“l”, “e”)?
A) Heeeo
B) Heelo
C) Heleo
D) None
Answer: Heeeo
Q61: To retrieve the character at index 3 from string s=”Hello” what command do we execute (multiple
answers allowed)?
A) s[]
B) s.getitem(3)
C) s.__getitem__(3)
D) s.getItem(3)
Answer: s.__getitem__(3)
Q62: To return the length of string s what command do we execute?
A) s.__len__()
B) len(s)
C) size(s)
D) s.size()
Answer: s.__len__()

9|P ag e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Q63: If a class defines the __str__(self) method, for an object obj for the class, you can use which
command to invoke the __str__ method.
A) obj.__str__()
B) str(obj)
C) print obj
D) all of the mentioned
Answer: all of the mentioned
Q64: To check whether string s1 contains another string s2, use ________
A) s1.__contains__(s2)
B) s2 in s1
C) s1.contains(s2)
D) si.in(s2)
Answer: s1.__contains__(s2)
Q65: Suppose i is 5 and j is 4, i + j is same as ________
A) i.__add(j)
B) i.__add__(j)
C) i.__Add(j)
D) i.__ADD(j)
Answer: i.__add__(j)
Q66: What function do you use to read a string?
A) input(“Enter a string”)
B) eval(input(“Enter a string”))
C) enter(“Enter a string”)
D) eval(enter(“Enter a string”))
Answer: input(“Enter a string”)
Q67: Suppose x is 345.3546, what is format(x, “10.3f”) (_ indicates space).
A) __345.355
B) ___345.355
C) ____345.355
D) _____345.354
Answer: ___345.355
Q68: What will be the output of the following Python code? print("abc DEF".capitalize())
A) abc def
B) ABC DEF
C) Abc def
D) Abc Def
Answer: Abc def
Q69: What will be the output of the following Python code? print("abc. DEF".capitalize())
A) abc. def
B) ABC. DEF
C) Abc. def
D) Abc. Def
Answer: Abc. def

10 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Q70: What will be the output of the following Python code? print("abcdef".center())
A) cd
B) abcdef
C) error
D) none of the mentioned
Answer: error
Q71: What will be the output of the following Python code? print("abcdef".center(0))
A) cd
B) abcdef
C) error
D) none of the mentioned
Answer: abcdef
Q72: What will be the output of the following Python code? print('*', "abcdef".center(7), '*')
A) * abcdef *
B) * abcdef *
C) *abcdef *
D) * abcdef*
Answer: * abcdef *
Q73: What will be the output of the following Python code? print('*', "abcdef".center(7), '*', sep='')
A) * abcdef *
B) * abcdef *
C) *abcdef *
D) * abcdef*
Answer: * abcdef*
Q74: What will be the output of the following Python code? print("xyyzxyzxzxyy".count('yy'))
A) 2
B) 0
C) error
D) none of the mentioned
Answer: 2
Q75: What will be the output of the following Python code? print("xyyzxyzxzxyy".count('xyy', 0, 100))
A) 2
B) 0
C) 1
D) error
Answer: 2

76. What is the maximum possible length of an identifier?


a) 16
b) 32
c) 64
d) None of these above
Ans : None of these above

11 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE

77. In which year was the Python language developed?


a) 1995
b) 1972
c) 1981
d) 1989
Ans : 1989

78. In which language is Python written?


a) English
b) PHP
c) C
d) All of the above
Ans : C

79. Which one of the following is the correct extension of the Python file?
a) .py
b) .python
c) .p
d) None of these
Ans : .py

80. In which year was the Python 3.0 version developed?


a) 2008
b) 2000
c) 2010
d) 2005
Ans : 2008

81. What do we use to define a block of code in Python language?


a) Key
b) Brackets
c) Indentation
d) None of these
Ans : Indentation

82. Which character is used in Python to make a single line comment?


a) /
b) //
c) #
d) !
Ans : #

12 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
83. Which of the following statements is correct regarding the object-oriented programming concept
in Python?
a) Classes are real-world entities while objects are not real
b) Objects are real-world entities while classes are not real
c) Both objects and classes are real-world entities
d) All of the above
Ans : Objects are real-world entities while classes are not real

84. What is the method inside the class in python language?


a) Object
b) Function
c) Attribute
d) Argument
Ans : Function

85. Which of the following declarations is incorrect?


a) _x = 2
b) __x = 3
c) __xyz__ = 5
d) None of these
Ans : None of these

86. Why does the name of local variables start with an underscore discouraged?
a) To identify the variable
b) It confuses the interpreter
c) It indicates a private variable of a class
d) None of these
Ans : It indicates a private variable of a class

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


a) val
b) raise
c) try
d) with
ans : val

88. Which of the following statements is correct for variable names in Python language?
a) All variable names must begin with an underscore.
b) Unlimited length
c) The variable name length is a maximum of 2.
d) All of the above
Ans : Unlimited length

13 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
89. Which of the following declarations is incorrect in python language?
a) xyzp = 5,000,000
b) x y z p = 5000 6000 7000 8000
c) x,y,z,p = 5000, 6000, 7000, 8000
d) x_y_z_p = 5,000,000
ans : x y z p = 5000 6000 7000 8000

90. Which of the following words cannot be a variable in python language?


a) _val
b) val
c) try
d) _try_
Ans : try

91. Which of the following operators is the correct option for power(ab)?
a) a ^ b
b) a**b
c) a ^ ^ b
d) a ^ * b
ans : a**b

92. Which of the following precedence order is correct in Python?


a) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
b) Multiplication, Division, Addition, Subtraction, Parentheses, Exponential
c) Division, Multiplication, Addition, Subtraction, Parentheses, Exponential
d) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
Ans : Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

93. Which one of the following has the same precedence level?
a) Division, Power, Multiplication, Addition and Subtraction
b) Division and Multiplication
c) Subtraction and Division
d) Power and Division
Ans : Division and Multiplication

94. Which one of the following has the highest precedence in the expression?
a) Division
b) Subtraction
c) Power
d) Parentheses
Ans : Parentheses

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

14 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a) val()
b) print()
c) print()
d) None of these
Ans : print()

96. Study the following function:


round(4.576)
What will be the output of this function?
a) 4
b) 5
c) 576
d) 5
Ans : 5

97. Which of the following is correctly evaluated for this function?


pow(x,y,z)
a) (x**y) / z
b) (x / y) * z
c) (x**y) % z
d) (x / y) / z
Ans : (x**y) / z

98. Study the following function:


all([2,4,0,6])
What will be the output of this function?
a) False
b) True
c) 0
d) Invalid code
Ans : False

99. Which one of the following syntaxes is the correct syntax to read from a simple text file stored in
''d:\java.txt''?
a) Infile = open(''d:\\java.txt'', ''r'')
b) Infile = open(file=''d:\\\java.txt'', ''r'')
c) Infile = open(''d:\java.txt'',''r'')
d) Infile = open.file(''d:\\java.txt'',''r'')
Ans : Infile = open(''d:\\java.txt'', ''r'')

100. Study the following statement:


>>>"a"+"bc"
What will be the output of this statement?

15 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a) a+bc
b) abc
c) a bc
d) a
ans : abc

101. Study the following code:


>>>"javatpoint"[5:]
What will be the output of this code?
a) javatpoint
b) java
c) point
d) None of these
Ans : point

102. Study the following code:


>>> print (r"\njavat\npoint")
What will be the output of this statement?
a) java
point
b) java point
c) \njavat\npoint
d) Print the letter r and then javat and then point
Ans : \njavat\npoint

103. Study the following statements:


>>> print(0xA + 0xB + 0xC)
What will be the output of this statement?
a) 33
b) 63
c) 0xA + 0xB + 0xC
d) None of these
Ans : 33

104. Study the following statements:


>>> print(ord('h') - ord('z'))
What will be the output of this statement?
a) 18
b) -18
c) 17
d) -17
Ans : -18

16 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
105. Which of the following option is not a core data type in the python language?
a) Dictionary
b) Lists
c) Class
d) All of the above
Ans : Dictionary

106. What error will occur when you execute the following code?
MANGO = APPLE
a) NameError
b) SyntaxError
c) TypeError
d) ValueError
Ans : NameError

107. What happens when '2' == 2 is executed?


a) False
b) Ture
c) ValueError occurs
d) TypeError occurs
Ans : False

108. Study the following statement


z = {"x":0, "y":1}
Which of the following is the correct statement?
a) x dictionary z is created
b) x and y are the keys of dictionary z
c) 0 and 1 are the values of dictionary z
d) All of the above
Ans : All of the above

109. Study the following program:


print(print(print("javatpoint")))
What will be the output of this program?
a) javatpoint None None
b) None None javatpoint
c) None javatpoint None
d) Javatpoint
Ans : javatpoint None None

110. Study the following program:


print(True ** False / True)
What will be the output of this program?

17 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a) True ** False / True
b) 1.0
c) 1 ** 0 / 1
d) None of the these
Ans : 1.0
111. Study the following program:
print(int(6 == 6.0) * 3 + 4 % 5)
What will be the output of this program?
a) 22
b) 18
c) 20
d) 7
Ans : 7

112. How many control statements python supports?


a) Four
b) Five
c) Three
d) None of the these
Ans : Three

113. How many keywords present in the python programming language?


a) 32
b) 61
c) 33
d) 27
Ans : 33

114. Which of the following arithmetic operators cannot be used with strings in python?
a) +
b) *
c) -
d) All of the mentioned
Ans : -

115. Study the following program:


print("java", 'point', sep='2')
What will be the output of this program?
a) javapoint2
b) japoint
c) java2point
d) javapoin2
ans : java2point

18 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE

116. Study the following program:


print('It\'s ok, don\'t worry')
What will be the output of this program?
a) It's ok, don't worry
b) It\'s ok, don\'t worry
c) SyntaxError: EOL while scanning string literal
d) SyntaxError: invalid syntax
Ans : It's ok, don't worry

117. Which of the following keywords is not reversed keyword in python?


a) None
b) class
c) goto
d) and
ans : goto

118. PVM is often called _________.


a) Python interpreter
b) Python compiler
c) Python volatile machine
d) Portable virtual machine
Ans : Python interpreter

119. Which of the following objects are present in the function header in python?
a) Function name and Parameters
b) Only function name
c) Only parameters
d) None of the these
Ans : Function name and Parameters

120. When a user does not use the return statement inside a function in Python, what will return the
function in that case.
a) 0
b) 1
c) None
d) No output
Ans : None

121. Which one of the following is the right way to call a function?
a) call function_name()
b) function function_name()
c) function_name()

19 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
d) None of the these
Ans : function_name()

122. Suppose a user wants to print the second value of an array, which has 5 elements. What will be
the syntax of the second value of the array?
a) array[2]
b) array[1]
c) array[-1]
d) array[-2]
ans : array[1]

123. Study the following expression:


str = [(1, 1), (2, 2), (3, 3)]
What type of data is in this expression?
a) String type
b) Array lists
c) List of tuples
d) str lists
ans : List of tuples

124. Which of the following statements is not valid regarding the variable in python?
a) The variable_name can begin with alphabets
b) The variable_name can begin with an underscore
c) The variable_name can begin with a number
d) None of the these
Ans : The variable_name can begin with a number

125. Which of the following statements is valid for "if statement"?


a) if f >= 12:
b) if (f >= 122)
c) if (f => 1222)
d) if f >= 12222
ans : if f >= 12:

126. Which of the following blocks allows you to test the code blocks for errors?
a) except block
b) try block
c) finally block
d) None of the these
Ans : try block

127. Which of the following statements would create a tuple in python?


a) mytuple = ("apple", "banana", "cherry")

20 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
b) mytuple[123] = ("apple", "banana", "cherry")
c) mytuple = ("2" * ("apple", "banana", "cherry"))
d) None of the these
Ans : mytuple = ("apple", "banana", "cherry")

128. Which of the following functions returns a list containing all matches?
a) find
b) findall
c) search
d) None of the these
Ans : findall

129. In the Python Programming Language, syntax error is detected by ______ at _________.
a) Interpreter / Compile time
b) Run time / Interpreter
c) Interpreter / Run time
d) Compile time / Run time
Ans : Interpreter / Run time

130. Which of the following blocks allows you to handle the errors?
a) except block
b) try block
c) finally block
d) None of the these
Ans : except block

131. When was Python released?


a) 16 October, 2001
b) 16 October 2000
c) 17 October 2000
d) 17 October 2001
Answer. b. 16 October 2000

132. When was Python 3.0 released?


a) 3 December 2008
b) 4 December 2008
c) 5 December 2008
d) 3 December 2010
Answer. a. 3 December 2008

133. What is Python?


a) A programming language
b) Computer language

21 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
c) Binary language
d) None of the above
Ans : A programming language

134. What does the name Python signify?


a) It is a snake
b) It is very difficult to use
c) Named after the British comedy group Monty Python
d) All of the above
Ans : Named after the British comedy group Monty Python

135. What are the people who specialize in Python called?


a) Pythonic
b) Unpythonic
c) Monty Python
d) Pythoniasts
Ans : Pythoniasts

136. What is the type of programming language supported by Python?


a) Object-oriented
b) Functional programming
c) Structured programming
d) All of the above
Ans : All of the above

137. When Python is dealing with identifiers, is it case sensitive?


a) Yes
b) No
c) Machine dependent
d) Can’t say
Ans : Yes

138. All the keywords in Python are in_


a) Lower case
b) Upper case
c) Capitalized
d) None of the above
Ans : None of the above

139. What does pip mean in Python?


a) Unlimited length
b) All private members must have leading and trailing underscores

22 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
c) Preferred Installer Program
d) None of the above
Ans : Preferred Installer Program

140. The built-in function in Python is:


a) Print ()
b) Seed ()
c) Sqrt ()
d) Factorial ()
Ans : Print ()

141. Which of the following definitions is the one for packages in Python?
a) A set of main modules
b) A folder of python modules
c) Set of programs making use of python modules
d) Number of files containing python definitions and statements
Ans : A folder of python modules

142. What is the order in which namespaces in Python looks for an identifier?
a) First, the python searches for the built-in namespace, then the global namespace and then the
local namespace
b) Python first searches for the built-in namespace, then local and finally the global namespace
c) Python first searches for local namespace, then global namespace and finally the built-in
namespace
d) Python searches for the global namespace, followed by the local namespace and finally the built-
in namespace.
Ans : Python first searches for local namespace, then global namespace and finally the built-in
namespace

143. Which of the following is not a keyword used in Python language?


a) Pass
b) Eval
c) Assert
d) Nonlocal
Ans : Eval

144. Which of the following is the use of function in python?


a) Functions do not provide better modularity for applications
b) One can’t create our own functions
c) Functions are reusable pieces of programs
d) All of the above
Ans : Functions are reusable pieces of programs

23 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
145. What is Python code-compiled or interpreted?
a) The code is both compiled and interpreted
b) Neither compiled nor interpreted
c) Only compiled
d) Only interpreted
Ans : Neither compiled nor interpreted

146. What is the function of pickling in python?


a) Conversion of a python object
b) Conversion of database into list
c) Conversion of byte stream into python object hierarchy
d) Conversion of list into database
Ans : Conversion of a python object

147. Which of the following is the use of the function id() in python?
a) Every object does not have a unique id in Python
b) The id function in python returns the identity of the object
c) None
d) All
Ans : The id function in python returns the identity of the object

148. Python is a ___object-oriented programming language.


a) Special purpose
b) General purpose
c) Medium level programming language
d) All of the mentioned above
Answer: B) General purpose

149. Amongst which of the following is / are the application areas of Python programming?
a) Web Development
b) Game Development
c) Artificial Intelligence and Machine Learning
d) All of the mentioned above
Answer: D) All of the mentioned above

150. Find the invalid variable among the following:


a. 1st_string
b. my_string_1
c. _
d. foo
Answer: (a) 1st_string

151. Which one of these is incorrect?

24 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a. float(‘nan’)
b. float(‘inf’)
c. float(’12+34′)
d. float(’56’+’78’)
Answer: (c) float(’12+34′)

152. The value of the Python expression given below would be:
4+2**5//10
a. 77
b. 0
c. 3
d. 7
Answer: (d) 7

153. The return value for trunc() would be:


a. bool
b. float
c. int
d. None
Answer: (c) int

154. What is the output of the Python code given below, if the date of the system is June 21st, 2017
(Wednesday)?
[] or {}
{} or []
a.
[] []
b.
[]
{}
c.
{}
{}
d.
{}
[]
Answer: (d)
{}
[]

155. The output of this Python code would be:


s='{0}, {1}, and {2}’
s.format(‘hi’, ‘great’, ‘day’)

25 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a. ‘hi, great, and day’
b. ‘hi great and day’
c. ‘hi, great, day’
d. Error
Answer: (a) ‘hi, great, and day’

156. The output of this Python code would be:


print(“mno. PQR”.capitalize())
a. Mno. Pqr
b. Mno. pqr
c. MNO. PQR
d. mno. pqr
Answer: (b) Mno. pqr

157. Which arithmetic operators can we NOT use with strings?


a. –
b. +
c. *
d. All of the above
Answer: (a) –

158. Which function do we use to shuffle a list(say list1)?


a. shuffle(list1)
b. list1.shuffle()
c. random.shuffleList(list1)
d. random.shuffle(list1)
Answer: (d) random.shuffle(list1)

159. Which function removes a set’s first and the last element from a list?
a. pop
b. remove
c. dispose
d. discard
Answer: (a) pop

160. Which one of these is NOT true about recursion?


a. We can replace a recursive function by a non-recursive function
b. The memory space taken by the recursive functions is more than that of non-recursive function
c. Running a recursive function is faster as compared to a non-recursive function
d. The process of recursion makes it easier for users to understand a program
Answer: (c) Running a recursive function is faster as compared to a non-recursive function

161. Which of these functions can NOT be defined under the sys module?

26 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a. sys.argv
b. sys.readline
c. sys.path
d. sys.platform
Answer: (b) sys.readline

162. Which function doesn’t accept any argument?


a. re.compile
b. re.findall
c. re.match
d. re.purge
Answer: (d) re.purge

163. In Python, the primary use of the tell() method is that:


a. within the file, it tells the end position
b. within the file, it tells the current position
c. it tells us if the file is opened
d. none of the above
Answer: (b) within the file, it tells the current position

164. The hasattr(obj,name) is used to:


a. check if any specific attribute exists
b. set an attribute
c. access the object’s attribute
d. delete an attribute
Answer: (a) check if any specific attribute exists

165. In Python, find which one isn’t an exception handling keyword.


a. accept
b. finally
c. try
d. except
Answer: (a) accept

166. Which of the following commands will create a list?


a) list1 = list()
b) list1 = []
c) list1 = list([1, 2, 3])
d) all of the mentioned
Ans : d) all of the mentioned

167. What is the output when we execute list(“hello”)?


a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

27 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
b) [‘hello’]
c) [‘llo’]
d) [‘olleh’]
Ans : a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

168. list, tuple, and range are the ___ of Data Types.
a) Sequence Types
b) Binary Types
c) Boolean Types
d) None of the mentioned above
Answer: A) Sequence Types

169. Float type of data type is represented by the float class.


a) True
b) False
Answer: A) True

170. bytes, bytearray, memoryview are type of the ___ data type.
a) Mapping Type
b) Boolean Type
c) Binary Types
d) None of the mentioned above
Answer: C) Binary Types

171. The type() function can be used to get the data type of any object.
a) True
b) False
Answer: A) True

172. Binary data type is a fixed-width string of length bytes?


a) True
b) False
Answer: A) True

173. Varbinary data type returns variable-width string up to a length of max-length bytes?
a) TRUE
b) FALSE
Answer: A) TRUE

174. Amongst which of the following is / are the logical operators in Python?
a) and
b) or
c) not

28 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
d) All of the mentioned above
Answer: D) All of the mentioned above

175. Is Python supports exception handling?


a) Yes
b) No
Answer: A) Yes

176. What is the name of the operator ** in Python?


a) Exponentiation
b) Modulus
c) Floor division
d) None of the mentioned above
Answer: A) Exponentiation

177. The % operator returns the ___.


a) Quotient
b) Divisor
c) Remainder
d) None of the mentioned above
Answer: C) Remainder

178. Amongst which of the following is / are the method of list?


a) append()
b) extend()
c) insert()
d) All of the mentioned above
Answer: D) All of the mentioned above

179. The list.pop ([i]) removes the item at the given position in the list?
a) True
b) False
Answer: A) True

180. The list.index(x[, start[, end]]) is used to ___.


a) Return zero-based index in the list
b) Raises a ValueError if there is no such item
c) Both A and B
d) None of the mentioned above
Answer: C) Both A and B

181. Python Dictionary is used to store the data in a ___ format.


a) Key value pair

29 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
b) Group value pair
c) Select value pair
d) None of the mentioned above
Answer: A) Key value pair

182. Python Literals is used to define the data that is given in a variable or constant?
a) True
b) False
Answer: A) True

183. Conditional statements are also known as ___ statements.


a) Decision-making
b) Array
c) List
d) None of the mentioned above
Answer: A) Decision-making

184. The if statement is the most fundamental decision-making statement?


a) True
b) False
Answer: A) True

185. Amongst which of the following is / are the conditional statement in Python code?
a) if a<=100:
b) if (a >= 10)
c) if (a => 200)
d) None of the mentioned above
Answer: A) if a<=100:

186. Which of the following is not used as conditional statement in Python?


a) switch
b) if...else
c) elif
d) None of the mentioned above
Answer: A) switch

187. Which of the following is false regarding conditional statement in Python?


a) If-elif is the shortcut for the if-else chain
b) We use the dictionary to replace the Switch case statement
c) We cannot use python classes to implement the switch case statement
d) None of the mentioned above
Answer: C) We cannot use python classes to implement the switch case statement

30 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
188. In Python, an else statement comes right after the block after 'if'?
a) True
b) False
Answer: A) True

189. In a Python program, Nested if Statements denotes?


a) if statement inside another if statement
b) if statement outside the another if statement
c) Both A and B
d) None of the mentioned above
Answer: A) if statement inside another if statement

190. An ___ statement has less number of conditional checks than two successive ifs.
a) if else if
b) if elif
c) if-else
d) None of the mentioned above
Answer: C) if-else

191. In Python, the break and continue statements, together are called ___ statement.
a) Jump
b) goto
c) compound
d) None of the mentioned above
Answer: B) goto

192. The elif statement allows us to check multiple expressions.


a) True
b) False
Answer: A) True

193. If a condition is true the not operator is used to reverse the logical state?
a) True
b) False
Answer: A) True

194. Loops are known as ___ in programming.


a) Control flow statements
b) Conditional statements
c) Data structure statements
d) None of the mentioned above
Answer: A) Control flow statements

31 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
195. The for loop in Python is used to ___ over a sequence or other iterable objects.
a) Jump
b) Iterate
c) Switch
d) All of the mentioned above
Answer: B) Iterate

196. With the break statement we can stop the loop before it has looped through all the items?
a) True
b) False
Answer: A) True

197. The continue keyword is used to ___ the current iteration in a loop.
a) Initiate
b) Start
c) End
d) None of the mentioned above
Answer: C) End

198. Amongst which of the following is / are true about the while loop?
a) It continually executes the statements as long as the given condition is true
b) It first checks the condition and then jumps into the instructions
c) The loop stops running when the condition becomes fail, and control will move to the next line of
code.
d) All of the mentioned above
Answer: D) All of the mentioned above

199. The ___ is a built-in function that returns a range object that consists series of integer numbers,
which we can iterate using a for loop.
a) range()
b) set()
c) dictionary{}
d) None of the mentioned above
Answer: A) range()

200. The looping reduces the complexity of the problems to the ease of the problems?
a) True
b) False
Answer: A) True

201. The while loop is intended to be used in situations where we do not know how many iterations
will be required in advance?
a) True

32 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
b) False
Answer: A) True

202. Amongst which of the following is / are true with reference to loops in Python?
a) It allows for code reusability to be achieved.
b) By utilizing loops, we avoid having to write the same code over and over again.
c) We can traverse through the elements of data structures by utilizing looping.
d) All of the mentioned above
Answer: D) All of the mentioned above

203. A function is a group of related statements which designed specifically to perform a ___.
a) Write code
b) Specific task
c) Create executable file
d) None of the mentioned above
Answer: B) Specific task

204. Once we have defined a function, we can call it?


a) True
b) False
Answer: A) True

205. Amongst which of the following shows the types of function calls in Python?
a) Call by value
b) Call by reference
c) Both A and B
d) None of the mentioned above
Answer: C) Both A and B

206. Amongst which of the following is a function which does not have any name?
a) Del function
b) Show function
c) Lambda function
d) None of the mentioned above
Answer: C) Lambda function

207. Can we pass List as an argument in Python function?


a) Yes
b) No
Answer: A) Yes

208. A method refers to a function which is part of a class?


a) True

33 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
b) False
Answer: A) True

209. The return statement is used to exit a function?


a) True
b) False
Answer: A) True

210. Scope and lifetime of a variable declared in a function exist till the function exists?
a) True
b) False
Answer: A) True

211. File handling in Python refers the feature for reading data from the file and writing data into a
file?
a) True
b) False
Answer: A) True

212. Amongst which of the following is / are the key functions used for file handling in Python?
a) open() and close()
b) read() and write()
c) append()
d) All of the mentioned above
Answer: D) All of the mentioned above

213. Amongst which of the following is / are needed to open an existing file?
a) filename
b) mode
c) Both A and B
d) None of the mentioned above
Answer: C) Both A and B

214. Binary files are stored in the form of 0s and 1s?


a) True
b) False
Answer: A) True

215. The function file_object.close() is used to ___.


a) To open the existing file
b) To append in an opened file
c) To close an opened file
d) None of the mentioned above

34 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Answer: C) To close an opened file

216. Python always makes sure that any unwritten or unsaved data is written to the file before it is
closed?
a) True
b) False
Answer: A) True

217. The write() method takes a string as an argument and ___.


a) writes it to the text file
b) read from the text file
c) append in a text file
d) None of the mentioned above
Answer: A) writes it to the text file

218. The seek() method is used to ___.


a) Saves the file in secondary storage
b) Position the file object at a particular position in a file
c) Deletes the file form secondary storage
d) None of the mentioned above
Answer: B) Position the file object at a particular position in a file

219. Amongst which of the following function is / are used to create a file and writing data?
a) append()
b) open()
c) close()
d) None of the mentioned above
Answer: B) open()

220. The readline() is used to read the data line by line from the text file.
a) True
b) False
Answer: A) True

221. The module Pickle is used to ___.


a) Serializing Python object structure
b) De-serializing Python object structure
c) Both A and B
d) None of the mentioned above
Answer: C) Both A and B

222. Amongst which of the following is / are the method of convert Python objects for writing data in
a binary file?

35 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a) set() method
b) dump() method
c) load() method
d) None of the mentioned above
Answer: B) dump() method

223. Amongst which of the following is / are the method used to unpickling data from a binary file?
a) load()
b) set() method
c) dump() method
d) None of the mentioned above
Answer: B) set() method

224. A text file contains only textual information consisting of ___.


a) Alphabets
b) Numbers
c) Special symbols
d) All of the mentioned above
Answer: D) All of the mentioned above

225. The writelines() method is used to write multiple strings to a file?


a) True
b) False
Answer: A) True

226. The keyword we used to define a function is:


a) Define
b) call
c) def
d) function
ans : def

227. A function header consists of


a) function name
b) parameter list
c) return value
d) Both A and B
Ans : Both A and B

228. Functions are coming under two categories:


a) Nested function and Private function
b) Local function and Private function
c) Built-in function and User-define function

36 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
d) Nested function and local function
Ans : Built-in function and User-define function

229. The function, which is defined under a class, is called


a) Class
b) Function
c) Method
d) Module
Ans : Method

230. A function can be executed automatically without calling it


a) True
b) False
c) Depending on the python version
d) Depending on the type of the function
Ans : False

231. The variable which is defined inside a function is called


a) Local variable
b) Global variable
c) Both A and B
d) None of the above
Ans : Local variable

232. The variable which is defined outside the function is called


a) Local variable
b) Global variable
c) Both A and B
d) None of the above
Ans : Global variable

233. The output of bool(‘’) will return


a) True
b) False
c) Error
d) Nan
Ans : False

234. The output of bool(‘False’) will return


a) True
b) False
c) Error
d) Nan

37 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Ans : True

235. Parameters of a function can be defined


a) During the function creation
b) During the function calling
c) To find the bug in a function
d) None of the above
Ans : During the function creation

236. The output of int(False) should be


a) 1
b) 0
c) False
d) Error
Ans : 0

237. You can also create your own functions, these functions are called
a) In-build function
b) User-defined function
c) Nested function
d) Local function
Ans : User-defined function

238. What is a recursive function?


a) A function that calls other function
b) A function which calls itself
c) Both A and B
d) None of the above
Ans : A function which calls itself

239. We can do matrix and array operations in a list:


a) True
b) False
c) True under certain conditions
d) False under certain conditions
Ans : False

240. A list is a
a) Mutable collection of data
b) Immutable collection of data
c) Mutable but depend on the elements it contains
d) Immutable but depend on the elements it contains

38 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Ans : Mutable collection of data

241. The list is faster than a tuple


a) True
b) False
c) Both are taking a same amount of time
d) Sometimes it is true
Ans : False

242. What is the correct syntax for calling an instance method on a class named Game?
a) my_game = Game()self.my_game.roll_dice()
b) my_game = Game(self)
self.my_game.roll_dice()
c) my_game = Game(self) my_game.roll_dice(self)
d) my_game = Game()my_game.roll_dice()
ans : my_game = Game()my_game.roll_dice()

243. How to output the string “May the odds favor you” in Python?
a) print(“May the odds favor you”)
b) echo(“May the odds favor you”)
c) System.out(“May the odds favor you”)
d) printf(“May the odds favor you”)
ans : print(“May the odds favor you”)

244. How to create a variable in Python with a value 22.6?


a) int a = 22.6
b) a = 22.6
c) Integer a = 22.6
d) None of the above
Ans : a = 22.6

245. How to add a single-line comment in Python?


a) /* This is a comment */
b) !! This is a comment
c) // This is a comment
d) # This is a comment
Ans : # This is a comment

246. How to represent 261500000 as a floating number in Python?


a) 2.615E8
b) 261500000
c) 261.5E8
d) 2.6

39 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Ans : 2.615E8

247. Select the correct example of the complex datatype in Python


a) 3 + 2j
b) -100j
c) 5j
d) All of the above are correct
Ans : All of the above are correct

248. How to convert the uppercase letters in the string to lowercase in Python?
a) lowercase()
b) capitalize()
c) lower()
d) toLower()
ans : lower()

249. Which Python module is used to parse dates in almost any string format?
a) datetime module
b) time module
c) calendar module
d) dateutil module
ans : dateutil module

250. Which of the following is the correct way to indicate Hexadecimal Notation in Python?
a) str = ‘\62’
b) str = ’62’
c) str = “62”
d) str = ‘\x62’
ans : str = ‘\x62’

251. To begin slicing from the end of the string, which of the following is used in Python?
a) Indexing
b) Negative Indexing
c) Begin with the 0th index
d) Escape Characters
Ans : Negative Indexing

252. How to fetch characters from a given range in Python?


a) [:]
b) in operator
c) []
d) None of the above
Ans : [:]

40 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE

253. How to capitalize only the first letter of a sentence in Python?


a) uppercase() method
b) capitalize() method
c) upper() method
d) None of the above
Ans : capitalize() method

254. What is the correct way to get the maximum value from Tuple in Python?
a) print (max(mytuple));
b) print (maximum(mytuple));
c) print (mytuple.max());
d) print (mytuple.maximum);
ans : print (max(mytuple));

255. How to fetch and display only the keys of a Dictionary in Python?
a) print(mystock.keys())
b) print(mystock.key())
c) print(keys(mystock))
d) print(key(mystock))
ans : print(mystock.keys())

256. How to align a string centrally in Python?


a) align() method
b) center() method
c) fill() method
d) None of the above
Ans : center() method

257. How to set the tab size to 6 in Python Strings?


a) expandtabs(6)
b) tabs(6)
c) expand(6)
d) None of the above
Ans : expandtabs(6)

258. ___________ uses square brackets for comma-separated values in Python? Fill in the blanks with
a Python collection.
a) Lists
b) Dictionary
c) Tuples
d) None of the above
Ans : Lists

41 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE

259. Are Python Tuples faster than Lists?


a) TRUE
b) FALSE
Ans : TRUE

260. How to find the index of the first occurrence of a specific value “i”, from the string “This is my
website”?
a) str.find(“i”)
b) str.find(i)
c) str.index()
d) str.index(“i”)
ans : str.index(“i”)

261. How to display whether the date is AM/PM in Python?


a) Use the %H format code
b) Use the %p format code
c) Use the %y format code
d) Use the %I format code
Ans : Use the %p format code

262. Which of the following is the correct way to access a specific element from a Multi-Dimensional
List?
a) list[row_size:column_size]
b) list[row_size][column_size]
c) list[(row_size)(column_size)]
d) None of the above
Ans : list[row_size][column_size]

263. Which of the following Bitwise operators in Python shifts the left operand value to the right, by
the number of bits in the right operand? The rightmost bits while shifting fall off.
a) Bitwise XOR Operator
b) Bitwise Right Shift Operator
c) Bitwise Left Shift Operator
d) None of the Above
Ans : Bitwise Right Shift Operator

264. How to specify range of index in Python Tuples? Let’s say our tuple name is “mytuple”
a) print(mytuple[1:4])
b) print(mytuple[1 to 4])
c) print(mytuple[1-4])
d) print(mytuple[].slice[1:4])
ans : print(mytuple[1:4])

42 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE

265. How to correctly create a function in Python?


a) demoFunction()
b) def demoFunction()
c) function demoFunction()
d) void demoFunction()
ans : def demoFunction()

266. Which one of the following is a valid identifier declaration in Python?


a) str = “demo666”
b) str = “666”
c) str = “demo demo2”
d) str = “$$$666”
ans : str = “demo666”

267. How to check whether all the characters in a string is printable?


a) print() method
b) printable() method
c) isprintable() method
d) echo() method
ans : isprintable() method

268. How to delete an element in a Dictionary with a specific key. Let’s say we need to delete the key
“Price”
a) del dict[‘Price’]
b) del.dict[‘Price’]
c) del dict(‘Price’)
d) del.dict[‘Price’]
ans : del dict[‘Price’]

269. How to swap cases in Python i.e. lowercase to uppercase and vice versa?
a) casefold() method
b) swapcase() method
c) case() method
d) title() method
ans : swapcase() method

270. The def keyword is used in Python to _______?


a) Define a function name
b) Define a list
c) Define an array
d) Define a Dictionary
Ans : Define a function name

43 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE

271. Which of the following is used to empty the Dictionary in Python? Let’s say our dictionary name is
“mystock”.
a) mystock.del()
b) clear mystock
c) del mystock
d) mystock.clear()
ans : mystock.clear()

272. How to display only the day number of years in Python?


a) date.strftime(“%j”)
b) date.strftime(“%H”)
c) date.strftime(“%I”)
d) date.strftime(“%p”)
ans : date.strftime(“%j”)

273. What is used in Python functions, if you have no idea about the number of arguments to be
passed?
a) Keyword Arguments
b) Default Arguments
c) Required Arguments
d) Arbitrary Arguments
Ans : Arbitrary Arguments

274. What is the correct way to create a Dictionary in Python?


a) mystock = {“Product”: “Earphone”, “Price”: 800, “Quantity”: 50}
b) mystock = {“Product”- “Earphone”, “Price”-800, “Quantity”-50}
c) mystock = {Product[Earphone], Price[800], Quantity[50]}
d) None of the above
Ans : mystock = {“Product”: “Earphone”, “Price”: 800, “Quantity”: 50}

275. In Python Functions, what is to be used to skip arguments or even pass them in any order while
calling a function?
a) Keyword arguments
b) Default Arguments
c) Required Arguments
d) Arbitrary Arguments
Ans : Keyword arguments

276. How to get the total length of a Tuple in Python?


a) count() method
b) length() method
c) len() method

44 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
d) None of the above
Ans : len() method

277. How to access a value in Tuple?


a) mytuple(1)
b) mytuple{1}
c) mytuple[1]
d) None of the abov
Ans : mytuple[1]

278. What is to be used to create a Dictionary of arguments in a Python function?


a) Arbitrary arguments in Python (*args)
b) Arbitrary keyword arguments in Python (**args)
c) Keyword Arguments
d) Default Arguments
Ans : Arbitrary keyword arguments in Python (**args)

279. How to convert the lowercase letters in the string to uppercase in Python?
a) upper()
b) uppercase()
c) capitalize()
d) toUpper()
ans : upper()

280. What is the correct way to get the minimum value from a List in Python?
a) print (minimum(mylist));
b) print (min(mylist));
c) print (mylist.min());
d) print (mylist.minimum());
ans : print (min(mylist));

281. Is using a return statement optional in a Python Function?


a) Yes
b) No
Ans : Yes

282. Which of the following correctly convert int to float in Python?


a) res = float(10)
b) res = convertToFloat(10)
c) None of the above
Ans : res = float(10)

45 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE

283. How to get the type of a variable in Python?


a) print(typeOf(a))
b) print(typeof(a))
c) print(type(a))
d) None of the above
Ans : print(type(a))

284. How to compare two operands in Python and check for equality? Which operator is to be used?
a) =
b) in operator
c) is operator
d) == (Answer)
Ans : == (Answer)

285. What is the correct way to get minimum value from Tuple?
a) print (min(mytuple));
b) print (minimum(mytuple));
c) print (mytuple.min());
d) print (mytuple.minimum);
ans : print (min(mytuple));

286. How to display only the current month’s number in Python?


a) date.strftime(“%H”)
b) date.strftime(“%I”)
c) date.strftime(“%p”)
d) date.strftime(“%m”)
ans : date.strftime(“%m”)

287. How to compare two objects and check whether they have the same memory locations?
a) is operator
b) in operator
c) **
d) Bitwise operators
Ans : is operator

288. How to fetch and display only the values of a Dictionary in Python?

46 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a) print(mystock.value())
b) print(mystock.values())
c) print(values(mystock))
d) print(value(mystock))
ans : print(mystock.value())

289. Which operator is used in Python to raise numbers to the power?


a) Bitwise Operators
b) Exponentiation Operator (**)
c) Identity Operator (is)
d) Membership Operators (in)
Ans : Exponentiation Operator (**)

290. Can we create a Tuple in Python without parenthesis?


a) TRUE
b) FALSE
Ans : TRUE

291. ____________ represents key-value pair in Python?


a) Tuples
b) Lists
c) Dictionary
d) All the Above
Ans : Dictionary

292. Which of the following Bitwise operators sets each bit to 1, if only one of them is 1, i.e. if only
one of the two operands is 1?
a) Bitwise XOR
b) Bitwise OR
c) Bitwise AND
d) Bitwise NOT
Ans : Bitwise XOR

293. What is the correct way to get the maximum value from a List in Python?
a) print (maximum(mylist));
b) print (mylist.max());
c) print (max(mylist));
d) print (mylist.maximum());

47 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
ans : print (max(mylist));

294. An example to correctly begin searching from the end range of index in Python Tuples. Let’s say
our Python Tuple has 4 elements
a) print(mytuple[-3 to -1])
b) print(mytuple[3-1])
c) print(mytuple[].slice[-3:-1])
d) print(mytuple[-3:-1])
ans : print(mytuple[-3:-1])

295. Which of the following Bitwise operators in Python shifts the left operand value to the left, by
the number of bits in the right operand? The leftmost bits while shifting fall off.
a) Bitwise XOR Operator
b) Bitwise Right Shift Operator
c) Bitwise Left Shift Operator
d) None of the Above
Ans : Bitwise Left Shift Operator

296. Can we update Tuples or any of its elements in Python after the assignment?
a) Yes
b) No
Ans : Yes

297. How to display only the current month’s name in Python?


a) date.strftime(“%H”)
b) date.strftime(“%B”)
c) date.strftime(“%m”)
d) date.strftime(“%d”)
ans : date.strftime(“%B”)

298. ___________ uses Parenthesis for comma-separated values in Python? Fill in the blanks with a
Python collection?
a) List
b) Tuples
c) None of the above
Ans : Tuples

48 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
299. How to create an empty Tuple in Python?
a) mytuple = ()
b) mytuple = (0)
c) mytuple = 0
d) mytuple =
ans : mytuple = ()

300. Can we have duplicate keys in the Python Dictionary?


a) TRUE
b) FALSE
Ans : FALSE

(THE END)

49 | P a g e

You might also like