Home  >  Q&A  >  body text

python的可选参数问题,零基础,处于自学状态,真的好困惑啊大神们

movies=["A","B",["C",["D"]]]

print_lol(movies,0)

def print_lol(the_list,level):
    for each_item in the_list:
        if isinstance(each_item,list):
           print_lol(each_item,level+1)
        else:
           for tab_stop in rang(level):
               print("\t",end='')
           print(each_item)

我想知道这个哪出错了,是这样的,这个问题的前面一点讲的是python语言的发布问题嘛,然后我看得一愣一愣的,看不懂,又叫我建文件夹有什么的,我真的不懂啊,然后往后看,讲的就是level这个参数,然后又讲了可选参数,它没有给出完整的代码出来,以上这个是我自己摸索得出的,就是不知道对不对,然后系统显示错误,可是我看不懂哇,然后想请大神赐教,我不知道和前面那个发布问题有没关系,

NameError                         Traceback (most recent call last)
NameError: name 'rang' is not defined

这个是错误提示

ringa_leeringa_lee2765 days ago657

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2018-01-22 19:17:26

    It’s been one year, time flies by, thank you php Chinese website! I learned a lot!!! Optional parameters of python

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:30:16

    should be range 而不是 rang

    Also, when asking questions about python, be sure to indicate Python2 还是 Python3

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:30:16

    Be familiar with the language’s error prompts and common error types.

    reply
    0
  • Cancelreply