wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Functions Quiz

Total questions: 45

Worksheet time: 23mins

Name
Class
Date
1.

What is the correct way to define a function in Python?

a)

function myfunc():

b)

def myfunc():

c)

func myfunc():

d)

define myfunc():

2.

What will the following code print? def add(x, y=5): return x + y print(add(10))

a)

15

b)

10

c)

5

d)

Error

3.

Which keyword is used to exit a function and return a value?

a)

stop

b)

exit

c)

return

d)

break

4.

What is the default return value of a Python function if no return statement is specified?

a)

0

b)

None

c)

False

d)

Empty string

5.

Which of the following is a valid function call?

a)

myfunc[]

b)

myfunc{}

c)

myfunc()

d)

myfunc<>

6.

What will the following code output? def func(a, b=2, c=3): return a + b + c print(func(4, c=5))

a)

11

b)

12

c)

14

d)

Error

7.

What will this function return? def f(x, y): pass print(f(2, 3))

a)

0

b)

None

c)

2

d)

Error

8.

Which of these functions is built-in in Python?

a)

sqrt()

b)

print()

c)

append()

d)

main()

9.

Which of these is NOT a valid function name?

a)

_func

b)

func1

c)

1func

d)

func_name

10.

What will the output be? def calc(a, b):

return a * b

print(calc(2, 'Hi'))

a)

HiHi

b)

HiHiHiHi

c)

2Hi

d)

Error

11.

Can a Python function return multiple values?

a)

No

b)

Yes, as a tuple

c)

Only one

d)

Only lists

12.

Which type of arguments must be passed after keyword arguments?

a)

Positional arguments

b)

Default arguments

c)

None

d)

All of them

13.

Which function is used to get user input?

a)

read()

b)

scan()

c)

input()

d)

enter()

14.

What is the scope of a variable declared inside a function?

a)

Global

b)

Local

c)

Module-wide

d)

Class-only

15.

What keyword is used to create an anonymous function?

a)

lambda

b)

def

c)

func

d)

anon

16.

What will this code print? def f(x=[]): x.append(1) return x print(f(), f())

a)

[1] [1]

b)

[1] [1, 1]

c)

[1, 1] [1, 1]

d)

Error

17.

A function that calls itself is known as:

a)

Inline function

b)

Recursive function

c)

Lambda function

d)

Generator

18.

Which statement about default arguments is TRUE?

a)

They must come after non-default arguments

b)

They can come before positional arguments

c)

They are mandatory

d)

They cannot be used in Python

19.

What is the keyword to specify function annotations?

a)

:

b)

->

c)

@

d)

#

20.

Which of these creates a list in Python?

a)

{1,2,3}

b)

(1,2,3)

c)

[1,2,3]

d)

<1,2,3>

21.

Lists in Python are:

a)

Immutable

b)

Mutable

c)

Fixed-size

d)

Constant

22.

What will be the output? lst = [1, 2, 3] print(lst[1])

a)

1

b)

2

c)

3

d)

Error

23.

Which method adds an item at the end of a list?

a)

add()

b)

insert()

c)

append()

d)

extend()

24.

What is the output? lst = [1,2,3] lst.append([4,5]) print(lst)

a)

[1,2,3,4,5]

b)

[1,2,3,[4,5]]

c)

[1,2,3,4,[5]]

d)

Error

25.

Which method is used to remove and return the last element?

a)

remove()

b)

del

c)

pop()

d)

discard()

26.

What is the result of len([1, [2,3], 4])?

a)

2

b)

3

c)

4

d)

Error

27.

What does list(range(3)) return?

a)

[1,2,3]

b)

[0,1,2]

c)

[0,1,2,3]

d)

Error

28.

Which operator is used to concatenate lists?

a)

+

b)

*

c)

&

d)

concat

29.

What will be the output? lst = [10,20,30] print(lst[::-1])

a)

[10,20,30]

b)

[30,20,10]

c)

[20,30,10]

d)

Error

30.

Which method removes all items from a list?

a)

delete()

b)

clear()

c)

remove()

d)

pop()

31.

Which method is used to add multiple elements at once?

a)

extend()

b)

append()

c)

insert()

d)

add()

32.

What will this print? lst = [1,2,3,4] print(lst[1:3])

a)

[1,2,3]

b)

[2,3]

c)

[2,3,4]

d)

[1,2]

33.

What happens when you do lst * 2 where lst = [1,2]?

a)

[1,2,1,2]

b)

[2,4]

c)

Error

d)

[1,2,2]

34.

Which method inserts an element at a specific index?

a)

add()

b)

insert()

c)

append()

d)

extend()

35.

Which of the following is TRUE about lists?

a)

They allow duplicates

b)

They are immutable

c)

They are unordered

d)

They cannot store different data types

36.

Which statement deletes the element at index 2?

a)

list.remove(2)

b)

del list[2]

c)

list.pop()

d)

list.delete(2)

37.

What will this print? lst = [1,2,3] print(max(lst))

a)

1

b)

2

c)

3

d)

Error

38.

Which function sorts a list permanently?

a)

sort()

b)

sorted()

c)

order()

d)

arrange()

39.

Which function returns a sorted copy of a list without modifying it?

a)

sort()

b)

sorted()

c)

copy()

d)

reverse()

40.

What is the output? lst = [1,2,3] lst.remove(2) print(lst)

a)

[1,3]

b)

[2,3]

c)

[1,2]

d)

Error

41.

What will be the output? lst = [1,2,3] print(sum(lst))

a)

5

b)

6

c)

123

d)

Error

42.

Which method reverses a list in place?

a)

reversed()

b)

reverse()

c)

[::-1]

d)

invert()

43.

What is the output of:

def f(x, y=5, z=10):

print(x, y, z)

f(1, z=20)

a)

1 5 20

b)

1 20 10

c)

Error

d)

1 10 20

44.

What is the output?

nums = [3, 1, 2]

print(sorted(nums), nums)

a)

[1, 2, 3] [3, 1, 2]

b)

[1, 2, 3] [1, 2, 3]

c)

Error

d)

[3, 1, 2] [1, 2, 3]

45.

What is the output?

x = [1, 2, 3]

y = x

y.reverse()

print(x, y)

a)

[3, 2, 1] [1, 2, 3]

b)

[1, 2, 3] [3, 2, 1]

c)

[3, 2, 1] [3, 2, 1]

d)

Error