Python:需要有关函数的帮助

时间:2020-04-29 14:55:01

标签: python function arguments typeerror required

list = [1]
list2 =[1]

def all():
 num = 3
  def first(new_num): #new_num = new_index  = 3
   if num not in list:
    list.append(num)
    new_index = list.index(num)
    first(new_index) #new_index = num = 3
   else:
    second(new_num) #assign new_num to the function second()
  def second(item): #item = new_num in function first(new_num)
    print("hello" ,  item)
first()

all()

在最底部有一个all(),但是我不知道为什么它不在里面

1 个答案:

答案 0 :(得分:2)

这是一个范围界定问题。

函数first位于函数all内部,如果它位于first外部,则不能调用all。您应该要做的是打all,然后在all内部打一个电话,启动all,就像这样:

first

除了缩进有点麻烦之外,您还应该对每个pep8使用4个空格标签进行缩进。

相关问题