Python NoneType object is not callable (beginner)
You want to pass the function object hi
to your loop()
function, not the result of a call to hi()
(which is None
since hi()
doesn't return anything).
So try this:
>>> loop(hi, 5)hihihihihi
Perhaps this will help you understand better:
>>> print hi()hiNone>>> print hi<function hi at 0x0000000002422648>
Why does it give me that error?
Because your first parameter you pass to the loop
function is None but your function is expecting an callable object, which None object isn't.
Therefore you have to pass the callable-object which is in your case the hi
function object.
def hi(): print 'hi'def loop(f, n): #f repeats n times if n<=0: return else: f() loop(f, n-1) loop(hi, 5)