Python NoneType object is not callable (beginner)

前端 未结 4 1745
傲寒
傲寒 2020-12-04 14:25

It tells me line 1 and line 5 (new to debugging/programming, not sure if that helps)

def hi():
    print(\'hi\')


def         


        
4条回答
  •  旧巷少年郎
    2020-12-04 14:56

    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)
    

提交回复
热议问题