Python MCQ’s on Function: SET 2

11. What will be the output of the following Python functions?

chr(‘97’)

chr(97)

a)

a
Error

b)

‘a’
a

c)

Error
a

d)

Error
Error

Check Answer

Answer: c
The built-in function chr() returns the alphabet corresponding to the value given as an argument. This function accepts only integer type values. In the first function, we have passed a string. Hence the first function throws an error.

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

complex(1+2j)

a) Error

b) 1

c) 2j

d) 1+2j

Check Answer

Answer: d
The built-in function complex() returns the argument in a complex form. Hence the output of the function shown above will be 1+2j.

13. What is the output of the function complex()?

a) 0j

b) 0+0j

c) 0

d) Error

Check Answer

Answer: a
The complex function returns 0j if both of the arguments are omitted, that is, if the function is in the form of complex() or complex(0), then the output will be 0j.

14. The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:

a) (a%b, a//b)

b) (a//b, a%b)

c) (a//b, a*b)

d) (a/b, a%b)

Check Answer

Answer: b
The function divmod(a,b) is evaluated as a//b, a%b, if both ‘a’ and ‘b’ are integers.

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

divmod(10.5,5)

divmod(2.4,1.2)

a)

(2.00, 0.50)
(2.00, 0.00)

b)

(2, 0.5)
(2, 0)

c)

(2.0, 0.5)
(2.0, 0.0)

d)

(2, 0.5)
(2)

Check Answer

Answer: c
See python documentation for the function divmod.

16. The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid.

a) True

b) False

Check Answer

Answer: a
When converting from a string, the string must not contain any blank spaces around the + or – operator. Hence the function complex(‘2 – 3j’) will result in an error.

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

list(enumerate([2, 3]))

a) Error

b) [(1, 2), (2, 3)]

c) [(0, 2), (1, 3)]

d) [(2, 3)]

Check Answer

Answer: c
The built-in function enumerate() accepts an iterable as an argument. The function shown in the above case returns containing pairs of the numbers given, starting from 0. Hence the output will be: [(0, 2), (1,3)].

18. What will be the output of the following Python functions?

x=3

eval(‘x^2’)

a) Error

b) 1

c) 9

d) 6

Check Answer

Answer: b
The function eval is use to evaluate the expression that it takes as an argument. In the above case, the eval() function is used to perform XOR operation between 3 and 2. Hence the output is 1.

19. What will be the output of the following Python functions?

float(‘1e-003’)

float(‘2e+003’)

a)

3.00

300

b)

0.001
2000.0

c)

0.001
200

d)

Error
2003

Check Answer

Answer: b
The output of the first function will be 0.001 and that of the second function will be 2000.0. The first function created a floating point number up to 3 decimal places and the second function adds 3 zeros after the given number.

20. Which of the following functions does not necessarily accept only iterables as arguments?

a) enumerate()

b) all()

c) chr()

d) max()

Check Answer

Answer: c
The functions enumerate(), all() and max() accept iterables as arguments whereas the function chr() throws an error on receiving an iterable as an argument. Also note that the function chr() accepts only integer values.

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