Functions & Scope · Question 4 · Easy

A lambda is given a default value for its second parameter. What does this code print?

power = lambda a, b=2: a ** b
print(power(3), power(2, 5))
  1. 6 10
  2. 9 32
  3. 9 10
  4. 9 25
Answer and explanation

Answer: B. 9 32

Explanation: power(3) uses the default b = 2, so 3 ** 2 = 9. power(2, 5) is 2 ** 5 = 32. ** is the power operator, not multiplication.

Previous: In Python, what value does a function give back when its body ends without… · Next: The function below collects any number of marks using *marks. What is printed?

Practise functions & scope

Try a fresh set of functions & scope questions with an explanation after every answer, free and without signing up: Functions & Scope practice. Or sit a full placement mock test.

More functions & scope questions

More python practice

Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge