Python MCQ’s on Function: SET 3

21. Which of the following functions accepts only integers as arguments?

a) ord()

b) min()

c) chr()

d) any()

Check Answer

Answer: c
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.

22. 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))

Check Answer

Answer: d
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].

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

float(‘ -12345\n’)

(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)

Check Answer

Answer: b
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.

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

ord(65)

ord(‘A’)

a)

A
65

b)

Error
65

c)

A
Error

d)

Error
Error

Check Answer

Answer: b
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.

25. 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

Check Answer

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

26. 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()

Check Answer

Answer: d
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.

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

hex(15)

a) f

b) 0xF

c) 0Xf

d) 0xf

Check Answer

Answer: d
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.

28. Which of the following functions does not throw an error?

a) ord()

b) ord(‘ ‘)

c) ord(”)

d) ord(“”)

Check Answer

Answer: b
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).

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

len([“hello”,2, 4, 6])

a) 4

b) 3

c) Error

d) 6

Check Answer

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

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

oct(7)

oct(‘7’)

a)

Error
07

b)

0o7
Error

c)

0o7
Error

d)

07
0o7

Check Answer

Answer: c
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.

Page  1  2  3  4  5  6  7

Python Interview Questions (MCQs)

We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.

Python MCQs on Variables and Operators Python MCQs on Precedence and Associativity
Python MCQs on Data Type Python MCQs on Boolean
Python MCQs on Bitwise Operators Python MCQs on Formatting and Advance Formatting
Python MCQs on Decorators Python MCQs on While and For Loops
Python MCQs on List Python MCQs on List Comprehension
Python MCQs on String Python MCQs on Tuple
Python MCQs on SET Python MCQs on Dictionary
Python MCQs on Functions Python MCQs on Argument Parsing
Python MCQs on Global and Local Variables Python MCQs on Recursion
Python MCQs on Mapping Functions Python MCQs on Modules
Python MCQs on Regular Expressions Python MCQs on Files
Python MCQs on Overloading Python MCQs on Classes and Objects
Python MCQs on Inheritance Python MCQs on Polymorphism and Encapsulation
Python MCQs on Exception Handling

Leave a Comment