wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python - Functions

Total questions: 11

Worksheet time: 6mins

Name
Class
Date
1.

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

2.

Which are the advantages of functions in python?

a)

Reducing duplication of code

b)

Decomposing complex problems into simpler pieces

c)

Improving clarity of the code

d)

All of the mentioned

3.

What are the two main types of functions?

a)

Custom function

b)

Built-in function & User defined function

c)

User function

d)

System function

4.

Where is function defined?

a)

Module

b)

Class

c)

Another function

d)

All of the mentioned

5.

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

a)

Module

b)

Class

c)

Another function

d)

Method

6.

Which of the following refers to mathematical function?

a)

sqrt

b)

rhombus

c)

add

d)

rhombus

7.

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

8.

What will be the output of the following Python code?

y = 6

z=lambda x: x * y

print(z(8))

a)

12

b)

36

c)

16

d)

48

9.

What will be the output of the following Python code?

def writer():

title = 'Sir'

name = (lambda x:title + ' ' + x)

return name


who = writer()

who('Arthur')

a)

Arthur Sir

b)

Sir Arthur

c)

Arthur

d)

None of the mentioned

10.

What is a variable defined inside a function referred to as?

a)

A global variable

b)

A volatile variable

c)

A local variable

d)

An automatic variable

11.

If a function doesn’t have a return statement, which of the following does the function return?

a)

int

b)

null

c)

None

d)

An exception is thrown without the return statement