It tells me line 1 and line 5 (new to debugging/programming, not sure if that helps)
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) hi f() TypeError: 'NoneType' object is not callable
Why does it give me this error?
The error “TypeError: 'NoneType' object is not iterable” occurs when you try to iterate over a NoneType object. Objects like list, tuple, and string are iterables, but not None. To solve this error, ensure you assign any values you want to iterate over to an iterable object.
How to fix typeerror: 'module' object is not callable? To fix this error, we need to change the import statement in “mycode.py” file and specify a specific function in our import statement.
The Python "TypeError: 'int' object is not callable" occurs when we try to call an integer value as a function. To solve the error, correct the assignment, make sure not to override the built-in int() function, and resolve any clashes between function and variable names.
The "TypeError: 'module' object is not callable" means that we are trying to call a module object instead of a function or a class. To solve the error, we have to access an attribute on the module object that points to the specific function or class.
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) hi hi hi hi hi
Perhaps this will help you understand better:
>>> print hi() hi None >>> print hi <function hi at 0x0000000002422648>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With