Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我不明白为什么列表在成功执行后也不创建?_Python_Python 3.x_List_Function - Fatal编程技术网

Python 我不明白为什么列表在成功执行后也不创建?

Python 我不明白为什么列表在成功执行后也不创建?,python,python-3.x,list,function,Python,Python 3.x,List,Function,当我在IDE中运行这个时,列表被创建,但列表是空的,我如何解决这个问题 >>> def findnum(n,m): print('hellow') l=list(range(n,m)) >>> findnum(1,10) hellow >>> l [] 从函数返回列表,并将其放入单独的变量中。这里,l是仅在函数范围内具有数据的列表。以下代码段可能会有所帮助: >>> def find

当我在IDE中运行这个时,列表被创建,但列表是空的,我如何解决这个问题

>>> def findnum(n,m):
          print('hellow')
          l=list(range(n,m))
>>> findnum(1,10)
hellow
>>> l
[]

从函数返回列表,并将其放入单独的变量中。这里,l是仅在函数范围内具有数据的列表。以下代码段可能会有所帮助:

>>> def findnum(n,m):
      print('hellow')
      l=list(range(n,m))
      return l
>>> l = findnum(1,10)

您没有从函数返回任何内容,因此l是findnum的本地。。。try:l=findnum1,10,在findnum结束时返回l。这是初级编程,因此您可能需要阅读更多的介绍性材料。这与单独的文件编写(我的意思是键入并保存在findnum.py之类的文件中)的工作原理相同吗