Reputation: 157
def x(n):
return lambda a: print(a)
print(x(1)(2))
this outputs: 2 None
What is this None for? I don't understand the flow here...
Upvotes: 2
Views: 66
Reputation: 26037
What you need is:
def x(n):
return lambda a: a
print(x(1)(2))
When you do return lambda a: print(a)
, you print a
as well as return what print()
returns which you print when you call the function. print()
statement returns a None
. See:
print(print(1))
# 1
# None
Upvotes: 4