250+ TOP MCQs on Built-in Functions and Answers

Python Multiple Choice Questions on “Built-in Functions – 3”.

1. Which of the following functions accepts only integers as arguments?
a) ord()
b) min()
c) chr()
d) any()

Answer: c
Clarification: The function chr() accepts only integers as arguments. The function ord() accepts only strings. The functions min() and max() can accept floating point as well as integer arguments.

2. Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order, which of the following methods should be used?
a) reverse(l)
b) list(reverse[(l)])
c) reversed(l)
d) list(reversed(l))

Answer: d
Clarification: The built-in function reversed() can be used to reverse the elements of a list. This function accepts only an iterable as an argument. To print the output in the form of a list, we use: list(reversed(l)). The output will be: [4,3,2].

3. What will be the output of the following Python function?

(Note that the number of blank spaces before the number is 5)
a)   -12345.0 (5 blank spaces before the number)
b) -12345.0
c) Error
d) -12345.000000000…. (infinite decimal places)

Answer: b
Clarification: The function float() will remove all the blank spaces and convert the integer to a floating point number. Hence the output will be: -12345.0.

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

a)

A
65

b)

Error
65

c)

A
Error

d)

Error
Error

View Answer

Answer: b
Clarification: The built-in function ord() is used to return the ASCII value of the alphabet passed to it as an argument. Hence the first function results in an error and the output of the second function is 65.

  250+ TOP MCQs on Python Strings and Answers

 

5. What will be the output of the following Python function?

float(‘-infinity’)
float(‘inf’)

a)

–inf
inf

b)

–infinity
inf

c)

Error
Error

d)

Error
Junk value

View Answer

Answer: a
Clarification: The output of the first function will be –inf and that of the second function will be inf.

 

6. Which of the following functions will not result in an error when no arguments are passed to it?
a) min()
b) divmod()
c) all()
d) float()

Answer: d
Clarification: The built-in functions min(), max(), divmod(), ord(), any(), all() etc throw an error when no arguments are passed to them. However there are some built-in functions like float(), complex() etc which do not throw an error when no arguments are passed to them. The output of float() is 0.0.

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

a) f
b) 0xF
c) 0Xf
d) 0xf

Answer: d
Clarification: The function hex() is used to convert the given argument into its hexadecimal representation, in lower case. Hence the output of the function hex(15) is 0xf.

8. Which of the following functions does not throw an error?
a) ord()
b) ord(‘ ‘)
c) ord(”)
d) ord(“”)

Answer: b
Clarification: The function ord() accepts a character. Hence ord(), ord(”) and ord(“”) throw errors. However the function ord(‘ ‘) does not throw an error because in this case, we are actually passing a blank space as an argument. The output of ord(‘ ‘) is 32 (ASCII value corresponding to blank space).

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

  250+ TOP MCQs on Python Global vs Local Variables and Answers

a) 4
b) 3
c) Error
d) 6

Answer: a
Clarification: The function len() returns the length of the number of elements in the iterable. Therefore the output of the function shown above is 4.

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

a)

Error
07

b)

0o7
Error

c)

0o7
Error

d)

07
0o7

View Answer

Answer: c
Clarification: The function oct() is used to convert its argument into octal form. This function does not accept strings. Hence the second function results in an error while the output of the first function is 0o7.

 

 

Leave a Comment

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

Scroll to Top