LearnFrenzy
Sign in Take a free test

Functions · Exercise 1 of 4

Functions Functions MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on Python functions: return and None, default and keyword arguments, *args and **kwargs, the mutable default trap, scope, global and nonlocal. Pick an option to check your answer instantly.

Question 11 Medium

A function appends to a list passed to it. What does the caller see?

A No change, because Python copies arguments
B An error
C Only if the function returns the list
D The appended item, because the parameter refers to the same list object
Question page & discussion
Question 12 Hard

Why does x = 1 followed by def f(): print(x); x = 2 raise UnboundLocalError when f() is called?

A print cannot read globals
B x = 2 is a syntax error
C Functions cannot use variables named x
D The assignment makes x local for the whole function, so print(x) reads a local that has no value yet
Question page & discussion
Question 13 Medium

What does f(*[1, 2], **{"c": 3}) pass to f?

A f([1, 2], {"c": 3})
B f(1, 2, 3)
C f((1, 2), c=3)
D f(1, 2, c=3)
Question page & discussion
Question 14 Easy

Which of these is NOT possible with a Python function?

A Assigning it to another variable
B Changing its body by assigning to f()
C Passing it as an argument
D Storing it in a list
Question page & discussion
Question 15 Easy

Why is return usually better than print inside a function?

A print is slower
B print is not allowed in functions
C The caller can use the returned value in further calculations; a printed value is only shown
D return also prints the value
Question page & discussion
Up next · Exercise 2Predict the Output15 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links