Python MCQ



Q1.Which of the following is the use of id() function in python ?
  1. Every object doesn’t have a unique id
  2. Id returns the identity of the object
  3. All of the mentioned
  4. None of the mentioned.

Answer:- (2).
Q2.All keywords in Python are in ?
  1. Upper Case
  2. Lower Case
  3. Capitalized
  4. None of the mentioned.

Answer:- (4).
Q3. What is the return type of function id ?
  1. float
  2. bool
  3. dict
  4. int

Answer:- (4).
Q4. Which of the following data types is not supported in python ?
  1. String
  2. Numbers
  3. slice
  4. list

Answer:- (3).
Q5. which are the reserved keywords in python ?
  1. else
  2. raise
  3. import
  4. all of the above

Answer:- (4).
Q6. Which statement is correct ?
  1. List is mutable & Tuple is immutable
  2. List is immutable & Tuple is mutable
  3. Both are Mutable.
  4. Both are Immutable

Answer:- (1).
Q7.What is the maximum possible length of an identifier ?
  1. 32
  2. 63
  3. 79
  4. 31

Answer:- (4).
Q8.What will be the output of 7^10 in python ?
  1. 13
  2. 15
  3. 2
  4. none of these

Answer:- (1).
Q9.Which of the following refers to mathematical function ?
  1. sqrt
  2. add
  3. math
  4. sum

Answer:- (1).
Q10.Which one of these is floor division operator ?
  1. /
  2. //
  3. %
  4. $

Answer:- (2).
Q11.Python supports the creation of anonymous functions at runtime, using a construct called __________ ?
  1. pi
  2. anonymous
  3. lambda
  4. none of the mentioned.

Answer:- (3).
Explanation :Python supports the creation of anonymous functions (i.e. functions that are not bound to a name) at runtime, using a construct called lambda. Lambda functions are restricted to a single expression. They can be used wherever normal functions can be used.
Q12.what does pip stands for python ?
  1. Unlimited length
  2. all private members must have leading and trailing underscores.
  3. preferred installer program
  4. none of the mentioned.

Answer:- (3).
Q13. What is the order of precedence in Python ?
  1. Exponential, Parantheses, Multiplication, Division, Addition, Substraction
  2. Exponential, Parantheses, Division, Multiplication, Addition, Substraction
  3. Parantheses, Exponential, Multiplication, Division, Substraction, Addition
  4. Parantheses, Exponential, Multiplication, Division, Addition, Substraction

Answer:- (4).
Explanation :For order of precedence, just remember this PEMDAS (similar to BODMAS).
Q14. Which of the following functions is a built-in function in python ?
  1. factorial()
  2. print()
  3. seed()
  4. sqrt()

Answer:- (2).
Explanation :The function seed is a function which is present in the random module. The functions sqrt and factorial are a part of the math module. The print function is a built-in function which prints a value directly to the system output.
Q15. Which of these is the definition for packages in Python ?
  1. a set of main module
  2. a folder of python modules
  3. a number of files containing python definitions and statements
  4. a set of programs making use of Python modules

Answer:- (2).
Explanation :A folder of python programs is called as a package of modules.
Q16. Which function is called when the following python program is executed ?
f = foo()
format(f)
  1. str()
  2. format()
  3. _str_()
  4. _format_()

Answer:- (3).
Explanation :Both str(f) and format(f) call f.
Q17. Which one of the following is not a keyword in python language ?
  1. pass
  2. eval
  3. assert
  4. nonlocal

Answer:- (2).
Explanation :Eval can be used as a variable.
Q18.what will be the output of the following Python code ?
print("abc. DEF .capitalize())
  1. Abc. def
  2. abc. def
  3. Abc. Def
  4. ABC. DEF

Answer:- (1).
Explanation :The first letter of the string is converted to uppercase and the other are converted to lowercase.
Q19. Which of the following python statements will result in the output: 6 ?
A=[[1, 2, 3],
  [4, 5, 6]
  [7, 8, 9]]
  1. A[2][1]
  2. A[1][2]
  3. A[3][2]
  4. A[2][3]

Answer:- (2).
Explanation :The output that is required is 6, that is, row 2, item 3.This position is represented by A[1][2].
Q20.What will be the output of the following python code snippet ?
z=set('abc$de')
'a' in z
  1. Error
  2. True
  3. False
  4. No output

Answer:- (2).
Explanation : The code shown above is used to check whether a particular item is a part of a given set or not. Since 'a' is a part of the set z, the output is true. Note that this code would result in an error in the absence of the quote.
Q21.what are the two main types of functions in python ?
  1. system function
  2. custom function
  3. built in function & user defined function
  4. user function

Answer:- (3).
Q22.What will be the output of the following Python Code ?
print("Hello {0[0]} and {0[1]}" .format(('foo', 'bin')))
  1. Hello('foo', 'bin') and ('foo', 'bin')
  2. Error
  3. Hello foo and bin
  4. None of the mentioned.

Answer:- (3).
Explanation : The elements of the tuple are accessed by their indices.
Q23. The process of pickling in python includes_______ ?
  1. Conversion of a python object hierarchy into byte stream
  2. Conversion of a datatable into a list
  3. Conversion of a byte stream into python object hierarchy
  4. Conversion of a list into a datatable

Answer:- (1).
Explanation : Pickling is the process of sterilizing a python object, that is, conversion of a byte stream into python object hierarchy. The reverse of this process in known as unpickling.
Q24. What will be the output of the following python code ?
def foo():
try:
return 1
finally:
return 2
k= foo()
print(k)
  1. error, there is more than one return statement in a single try-finally block
  2. 3
  3. 2
  4. 1

Answer:- (3).
Explanation : The finally block is executed even there is a return statement in the try block.
Q25.Which keyword is used for function ?
  1. Fun
  2. Define
  3. Def
  4. Function

Answer:- (C).