LearnFrenzy
Sign in Take a free test

Functions · Predict the Output · Question 12

Using a function as an object Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following Python program?

main.py
def sq(x):
    return x * x

f = sq
print(f(4), f.__name__, list(map(sq, [1, 2, 3])))
  • A 16 f [1, 4, 9]
  • B sq 16 [1, 4, 9]
  • C TypeError
  • D 16 sq [1, 4, 9] Correct
Correct Answer: Option D

f is just another name for the same function object, whose __name__ is still "sq".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links