Functions & Scope · Question 12 · Medium

A function is passed to another function as an argument. What does twice print here?

def twice(fn, value):
    return fn(fn(value))

print(twice(lambda n: n * 3, 2))
  1. 6
  2. 12
  3. 36
  4. 18
Answer and explanation

Answer: D. 18

Explanation: Functions are objects, so the lambda can be passed as fn. The inner call gives 2 × 3 = 6 and the outer call gives 6 × 3 = 18.

Previous: This recursive function steps down by 2 on every call. What value is printed… · Next: Two counters are built from the same closure factory. What does the last line…

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