Python Multiple Choice Questions – Built-in Functions

Python Multiple Choice Questions & Answers (MCQs) focuses on “Built-in Functions”.

Q 1. Which of the following functions is a built-in function in python?
A. seed()
B. sqrt()
C. factorial()
D. print()

Show Answer Answer:-D. print()
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.

Q 2. What will be the output of the following Python expression?

round(4.576)
A. 4.5
B. 5
C. 4
D. 4.6

Show Answer Answer:-B. 5
Explanation This is a built-in function which rounds a number to give precision in decimal digits. In the above case, since the number of decimal places has not been specified, the decimal number is rounded off to a whole number. Hence the output will be 5.

Q 3. The function pow(x,y,z) is evaluated as:
A. (xy)z
B. (xy) / z c) C. (xy) % z
D. (x*y)z

Show Answer Answer:-D. (x*y)z
Explanation The built-in function pow() can accept two or three arguments. When it takes in two arguments, they are evaluated as xy. When it takes in three arguments, they are evaluated as (xy)%z.

Q 4. What will be the output of the following Python function?

all([2,4,0,6])
A. Error
B. True
C. False
D. 0

Show Answer Answer:-C. False
Explanation The function all returns false if any one of the elements of the iterable is zero and true if all the elements of the iterable are non zero. Hence the output of this function will be false.

Q 5. What will be the output of the following Python expression?

round(4.5676,2)?
A. 4.5
B. 4.6
C. 4.57
D. 4.56

Show Answer Answer:-C. 4.57
Explanation The function round is used to round off the given decimal number to the specified decimal places. In this case, the number should be rounded off to two decimal places. Hence the output will be 4.57.

Q 6. What will be the output of the following Python function?

any([2>8, 4>2, 1>2])
A. Error
B. True
C. False
D. 4>2

Show Answer Answer:-B. True
Explanation The built-in function any() returns true if any or more of the elements of the iterable is true (non zero), If all the elements are zero, it returns false.

Q 7. What will be the output of the following Python function?

import math
abs(math.sqrt(25))
A. 5.0
B. -5
C. 5
D. Error

Show Answer Answer:-A. 5.0
Explanation The abs() function prints the absolute value of the argument passed. For example: abs(-5)=5. Hence, in this case we get abs(5.0)=5.0.

Q 8. What will be the output of the following Python function?

sum(2,4,6)
sum([1,2,3])
A. Error, 6
B. 12, Error
C. 12, 6
D. Error, Error

Show Answer Answer:-A. Error, 6
Explanation The first function will result in an error because the function sum() is used to find the sum of iterable numbers. Hence the outcomes will be Error and 6 respectively.

Q 9. What will be the output of the following Python function?

all(3,0,4.2)
A. True
B. False
C. 0
D. Error

Show Answer Answer:-D. Error
Explanation The function all() returns ‘True’ if any one or more of the elements of the iterable are non zero. In the above case, the values are not iterable, hence an error is thrown.

Q 10. What will be the output of the following Python function?

min(max(False,-3,-4), 2,7)
A. 2
B. False
C. -3
D. -4

Show Answer Answer:-D. -4
Explanation The function max() is being used to find the maximum value from among -3, -4 and false. Since false amounts to the value zero, hence we are left with min(0, 2, 7) Hence the output is 0 (false).

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page