Python MCQ
Python MCQ
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
11 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
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
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
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
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
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
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
14 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a) val()
b) print()
c) print()
d) None of these
Ans : print()
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'')
15 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
a) a+bc
b) abc
c) a bc
d) a
ans : abc
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
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
114. Which of the following arithmetic operators cannot be used with strings in python?
a) +
b) *
c) -
d) All of the mentioned
Ans : -
18 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
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]
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
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
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
21 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
c) Binary language
d) None of the above
Ans : A programming language
22 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
c) Preferred Installer Program
d) None of the above
Ans : Preferred Installer Program
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
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
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
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
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
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)
{}
[]
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’
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
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
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
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
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
179. The list.pop ([i]) removes the item at the given position in the list?
a) True
b) False
Answer: A) True
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
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:
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
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
193. If a condition is true the not operator is used to reverse the logical state?
a) True
b) False
Answer: A) True
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
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
33 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
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
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
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
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
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
37 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Ans : True
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
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
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”)
39 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
Ans : 2.615E8
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
40 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
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())
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
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”)
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
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
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()
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
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
44 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
d) None of the above
Ans : len() method
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));
45 | P a g e
VELOCIS EDUCATION PYTHON MCQ MASTERY GUIDE
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));
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())
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
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 = ()
(THE END)
49 | P a g e