Python MCQ
Q1.Which of the following is the use of id() function in python ?
- Every object doesn’t have a unique id
- Id returns the identity of the object
- All of the mentioned
- None of the mentioned.
Answer:- (2).
- Upper Case
- Lower Case
- Capitalized
- None of the mentioned.
Answer:- (4).
- float
- bool
- dict
- int
Answer:- (4).
- String
- Numbers
- slice
- list
Answer:- (3).
- else
- raise
- import
- all of the above
Answer:- (4).
- List is mutable & Tuple is immutable
- List is immutable & Tuple is mutable
- Both are Mutable.
- Both are Immutable
Answer:- (1).
- 32
- 63
- 79
- 31
Answer:- (4).
- 13
- 15
- 2
- none of these
Answer:- (1).
- sqrt
- add
- math
- sum
Answer:- (1).
- /
- //
- %
- $
Answer:- (2).
- pi
- anonymous
- lambda
- 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.
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.
- Unlimited length
- all private members must have leading and trailing underscores.
- preferred installer program
- none of the mentioned.
Answer:- (3).
- Exponential, Parantheses, Multiplication, Division, Addition, Substraction
- Exponential, Parantheses, Division, Multiplication, Addition, Substraction
- Parantheses, Exponential, Multiplication, Division, Substraction, Addition
- Parantheses, Exponential, Multiplication, Division, Addition, Substraction
Answer:- (4).
Explanation :For order of precedence, just remember this PEMDAS (similar to BODMAS).
Explanation :For order of precedence, just remember this PEMDAS (similar to BODMAS).
- factorial()
- print()
- seed()
- 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.
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.
- a set of main module
- a folder of python modules
- a number of files containing python definitions and statements
- a set of programs making use of Python modules
Answer:- (2).
Explanation :A folder of python programs is called as a package of modules.
Explanation :A folder of python programs is called as a package of modules.
f = foo() format(f)
- str()
- format()
- _str_()
- _format_()
Answer:- (3).
Explanation :Both str(f) and format(f) call f.
Explanation :Both str(f) and format(f) call f.
- pass
- eval
- assert
- nonlocal
Answer:- (2).
Explanation :Eval can be used as a variable.
Explanation :Eval can be used as a variable.
print("abc. DEF .capitalize())
- Abc. def
- abc. def
- Abc. Def
- ABC. DEF
Answer:- (1).
Explanation :The first letter of the string is converted to uppercase and the other are converted to lowercase.
Explanation :The first letter of the string is converted to uppercase and the other are converted to lowercase.
A=[[1, 2, 3], [4, 5, 6] [7, 8, 9]]
- A[2][1]
- A[1][2]
- A[3][2]
- 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].
Explanation :The output that is required is 6, that is, row 2, item 3.This position is represented by A[1][2].
z=set('abc$de') 'a' in z
- Error
- True
- False
- 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.
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.
- system function
- custom function
- built in function & user defined function
- user function
Answer:- (3).
print("Hello {0[0]} and {0[1]}" .format(('foo', 'bin')))
- Hello('foo', 'bin') and ('foo', 'bin')
- Error
- Hello foo and bin
- None of the mentioned.
Answer:- (3).
Explanation : The elements of the tuple are accessed by their indices.
Explanation : The elements of the tuple are accessed by their indices.
- Conversion of a python object hierarchy into byte stream
- Conversion of a datatable into a list
- Conversion of a byte stream into python object hierarchy
- 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.
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.
def foo(): try: return 1 finally: return 2 k= foo() print(k)
- error, there is more than one return statement in a single try-finally block
- 3
- 2
- 1
Answer:- (3).
Explanation : The finally block is executed even there is a return statement in the try block.
Explanation : The finally block is executed even there is a return statement in the try block.
- Fun
- Define
- Def
- Function
Answer:- (C).
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.