Python Functions MCQ. Multiple Choice Questions related to Functions in Python Programming language.

**Python Functions MCQ**

**What will be the output of the following Python code ??**

**def sum(*args):**

**”’Function returns the sum **

**of all values”’**

**r = 0**

**for i in args:**

**r += i**

**return r**

**print sum.__doc__**

**print sum(1, 2, 3)**

**print sum(1, 2, 3, 4, 5)**

a) 6

15

b) 6

100

c) 123

12345

d) None of the mentioned

**Which of the following is a feature of DocString ??**

a) Provide a convenient way of associating documentation with Python modules, functions, classes, and methods

b) All functions should have a docstring

c) Docstrings can be accessed by the __doc__ attribute on objects

d) All of the mentioned

**What will be the output of the following Python code ??**

**def power(x, y=2):**

**r = 1**

**for i in range(y):**

**r = r * x**

**return r**

**print power(3)**

**print power(3, 3)**

a) 212

32

b) 9

27

c) 567

98

d) None of the mentioned

**What will be the output of the following Python ??**

**def maximum(x, y):**

**if x > y:**

**return x**

**elif x == y:**

**return ‘The numbers are equal’**

**else:**

**return y**

**print(maximum(2, 3))**

a) 2

b) 3

c) The numbers are equal

d) None of the mentioned

**Python Functions MCQ**

**What will be the output of the following ??**

**def C2F(c):**

**return c * 9/5 + 32**

**print C2F(100)**

**print C2F(0)**

a) 212

32

b) 314

24

c) 567

98

d) None of the mentioned

**What will be the output of the following code ??**

**def func(a, b=5, c=10):**

**print(‘a is’, a, ‘and b is’, b, ‘and c is’, c)**

**func(3, 7)**

**func(25, c = 24)**

**func(c = 50, a = 100)**

a) a is 7 and b is 3 and c is 10

a is 25 and b is 5 and c is 24

a is 5 and b is 100 and c is 50

b) a is 3 and b is 7 and c is 10

a is 5 and b is 25 and c is 24

a is 50 and b is 100 and c is 5

c) a is 3 and b is 7 and c is 10

a is 25 and b is 5 and c is 24

a is 100 and b is 5 and c is 50

d) None of the mentioned

**What will be the output of the following Python code ??**

**def cube(x):**

**return x * x * x **

**x = cube(3) **

**print x**

a) 9

b) 3

c) 27

d) 30

**What will be the output of the following Python code ??**

**def say(message, times = 1):**

**print(message * times)**

**say(‘Hello’)**

**say(‘World’, 5)**

a) Hello

WorldWorldWorldWorldWorld

b) Hello

World 5

c) Hello

World,World,World,World,World

d) Hello

HelloHelloHelloHelloHello

**Python Functions MCQ**

**Which of the following refers to mathematical function ??**

a) sqrt

b) rhombus

c) add

d) rhombus

**What will be the output of the following Python code ??**

**x = 50**

**def func():**

**global x**

**print(‘x is’, x)**

**x = 2**

**print(‘Changed global x to’, x)**

**func()**

**print(‘Value of x is’, x)**

a) x is 50

Changed global x to 2

Value of x is 50

b) x is 50

Changed global x to 2

Value of x is 2

c) x is 50

Changed global x to 50

Value of x is 50

d) None of the mentioned

**Which of the following is the use of id() function in python ??**

a) Id returns the identity of the object

b) Every object doesn’t have a unique id

c) All of the mentioned

d) None of the mentioned

**What will be the output of the following Python code ??**

**x = 50**

**def func(x):**

**print(‘x is’, x)**

**x = 2**

**print(‘Changed local x to’, x)**

**func(x)**

**print(‘x is now’, x)**

a) x is 50

Changed local x to 2

x is now 50

b) x is 50

Changed local x to 2

x is now 2

c) x is 50

Changed local x to 2

x is now 100

d) None of the mentioned

**Python Functions MCQ**

**What is called when a function is defined inside a class ??**

a) Module

b) Class

c) Another function

d) Method

**What will be the output of the following Python code ??**

**def printMax(a, b):**

**if a > b:**

**print(a, ‘is maximum’)**

**elif a == b:**

**print(a, ‘is equal to’, b)**

**else:**

**print(b, ‘is maximum’)**

**printMax(3, 4)**

a) 3

b) 4

c) 4 is maximum

d) None of the mentioned

**Where is function defined ??**

a) Module

b) Class

c) Another function

d) All of the mentioned