menu

Python Functions


1.

What is the output of the following code?
def square(x):
return x * x
result = square(5)
print(result)

5

10

25

50


2.

What is the output of the following code?
def my_function():global x
x = 5
x = x + 1
my_function()
print(x)

5

6

TypeError

None


3.

What is the output of the following code?
def my_function(x):
return x ** 2
numbers = [1, 2, 3, 4]
result = map(my_function, numbers)
print(list(result))

[1, 4, 9, 16]

[2, 4, 6, 8]

[0, 1, 4, 9

Error


4. What is the syntax to call a function in Python?

call function_name(arguments)

function_name(arguments)

function(arguments)

call function(arguments)


5.

What is the output of the following code?
def my_function(x, y):return x + y
result = my_function(y=2, x=3)
print(result)

5

2

3

1


6.

What is the output of the following code?
def my_function(a, b, c=0, d=0):return a + b + c + d
result = my_function(1, 2, 3, 4)
print(result)

3

6

10

5


7.

What is the output of the following code?
numbers = [1, 2, 3, 4, 5]
def is_even(x):return x % 2 == 0
even_numbers = filter(is_even, numbers)
print(list(even_numbers))

[1, 3, 5]

[2, 4]

[1, 2, 3, 4, 5]

[]


8.

What is the output of the following code?
def my_function(x, y):return x ** y
result = my_function(2, 3)
print(result)

5

8

6

1


9.

What is the output of the following code?
def my_function(**kwargs):return sum(kwargs.values())
result = my_function(a=1, b=2, c=3)
print(result)

1

4

6

3


10.

What is the output of the following code?
def my_function(*args):return sum(args)
result = my_function(1, 2, 3, 4)
print(result)

1

4

10

3