A Learning Portal from Recruitment India
Which of the following statements can be used to check, whether an object “obj” is an instance of class A or not?
obj.isinstance(A)
isinstance(A, obj)
isinstance(obj, A)
A.isinstance(obj)
Answer with explanation
Answer: Option CExplanation
isinstance(obj, A)
Workspace
Which one of the following is incorrect?
The variables used inside the function are called local variables.
In order to change the value of the global variable inside the function, the keyword global is used.
The local variables of a particular function can be used inside other functions, but these cannot be used in global space
The variables used outside a function are called global variables
Answer with explanation
Answer: Option CExplanation
The local variables of a particular function can be used inside other functions, but these cannot be used in global space is one of the following is incorrect
Workspace
Which of the following statements is most accurate for the declaration x = Circle()?
x contains an int value.
x contains an object of the Circle type.
x contains a reference to a Circle object.
You can assign an int value to x.
Answer with explanation
Answer: Option CExplanation
x contains a reference to a Circle object.
Workspace
Which of the following will print the pi value defined in math module?
print(pi)
print(math.pi)
from math import pi
print(pi)
from math import pi
print(math.pi)
Answer with explanation
Answer: Option CExplanation
from math import pi, print(pi) will print the pi value defined in the math module.
Workspace
What is the result of the expression if x=15 and y=12:
b1101
0b1101
12
1101
Answer with explanation
Answer: Option CExplanation
The symbol ‘&’ represents bitwise AND. This gives 1 if both the bits are equal to 1, else it gives 0. The binary form of 15 is 1111 and that of 12 is 1100. Hence on performing the bitwise AND operation, we get 1100, which is equal to 12.
Workspace
What is the output of the following?
a = [0, 1, 2, 3]
for a[0] in a:
print(a[0])
3 3 3 3
0 1 2 2
0 1 2 3
error
Answer with explanation
Answer: Option CExplanation
The value of a[0] changes in each iteration. Since the first value that it takes is itself, there is no visible error in the current example.
Workspace
What will be the output of the following Python code?
True = False
while True:
print(True)
break
True
False
None
none of the mentioned
Answer with explanation
Answer: Option DExplanation
SyntaxError, True is a keyword and it’s value cannot be changed.
Workspace
Which one of the following is the correct way of calling a function?
function function_name()
function_name()
call function_name()
ret function_name()
Answer with explanation
Answer: Option BExplanation
By using function_name() we can call a function in Python
Workspace
Select the correct option to draw a rectangle centred at 50,50 with width and height as 50, 70 respectively.
Canvas.create_rect(50,50,50,70)
Canvas.create_rect(50,70,50,50)
Canvas.create_rectangle(50,50,50,70)
Tkinter.create_rect(50,50,50,70)
Answer with explanation
Answer: Option CExplanation
Canvas.create_rectangle(50,50,50,70)
Workspace
In which part of memory does the system store the parameter and local variables of function call?
heap
stack
Uninitialized data segment
None of the above
Answer with explanation
Answer: Option BExplanation
Stack, where variables are stored, along with information that is saved each time a function is called. Each time a function is called, the address of where to return to and certain information about the caller’s environment, such as some of the machine registers, are saved on the stack.
Workspace
What will be displayed by the following code?
def f(value, values):
v = 1
values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])
1 1
1 44
3 1
3 44
Answer with explanation
Answer: Option DExplanation
The value of t=3 is passed in funcion f(value,values) , v [list] is passed as values in the same function.
The v is stored in values and values[0]=44 , changes the value at index[‘0’] in the list hence v=[44,2,3].
Workspace