我想这个代码Python的不理解如何解决
def out():
x=0
for line in range (x,10):
x += 1
return x
print out()
得到输出结果1
,如果我尝试这个代码
def out():
x=0
for line in range (x,10):
x += 1
return x
print out()
得到输出结果10
但是h ow我可以得到如下结果:1 2 3 4 5 6 7 8 9 10 带功能
return语句位于for循环中。在Python返回中,像任何其他语言一样,将函数返回到它的调用点。要阅读关于[Python文档](https://docs.python.org/2/reference/simple_stmts.html#grammar-token-return_stmt)的更多信息,如果您想返回'[1,2, 3,4,5,6,7,8,9,10]'然后使用一个变量列表'list = []'并附加一些东西给它。 'list.append(X)'。 –