A Learning Portal from Recruitment India
Which of the following is the use of id() function in python?
Id() returns the identity of the object.
Id() returns the size of object
Both A and B
None of the above
Answer with explanation
Answer: Option AExplanation
Id() returns the identity of the object.
Workspace
Given a function that does not return any value, what value is shown when executed at the shell?
int
None
bool
void
Answer with explanation
Answer: Option BExplanation
Python explicitly defines the None object that is returned if no value is specified.
Workspace
What is the output when following code is executed ?
print r”\nhello”
The output is
the letter r and then hello
\nhello
Error
a new line and hello
Answer with explanation
Answer: Option BExplanation
When prefixed with the letter ‘r’ or ‘R’ a string literal becomes a raw string and the escape sequences such as \n are not converted.
Workspace
What is the output for the following code ?
print(5*2**4)
40
80
100
TypeError
Answer with explanation
Answer: Option BExplanation
Exponential operator ** has more precedence than multiplication *
So 2**4 will be evaluated first, resulting in 16
Then 5 * 16 will produce 80 as output
Workspace
Which of the following will run without errors ?
round(45.8)
round(6352.898,2,5)
round()
round(7463.123,2,1)
Answer with explanation
Answer: Option AExplanation
Execute help(round) in the shell to get details of the parameters that are passed into the round function.
Workspace