[英]This is my program when i return num_list it doesn't work but when i put print it work smoothly,
This is my program when i return num_list it doesn't work but when i put print it work smoothly,my program and another friend program is exactly same but his program working and mine not.这是我的程序,当我返回 num_list 时它不起作用,但是当我打印它时,它运行顺利,我的程序和另一个朋友的程序完全相同,但他的程序工作而我的程序没有。
import random
def make_random_real():
num_list = []
for i in range(0, 10):
num_list.append(random.random())
return num_list
make_random_real()
In this version of the function, it just returns a value, so if you want to print it first you need to assign it to a variable like this:在这个版本的 function 中,它只是返回一个值,所以如果你想先打印它,你需要将它分配给这样的变量:
result = make_random_real()
then you can print(result)
which will show you the num_list in your function.然后您可以
print(result)
,它将显示 function 中的 num_list。
If you just want to print it without any assignment then just change return num_list
to print num_list
in your make_random_real()
function.如果您只想在没有任何分配的情况下打印它,那么只需在您的
make_random_real()
function 中将return num_list
更改为print num_list
num_list。
Assign the return value of the function to a value, so that you can print.将 function 的返回值赋值给一个值,这样就可以打印了。
The code is fine,代码很好,
only you are not able to view output because you are not printing the returned result from the function.只有您无法查看 output,因为您没有打印 function 的返回结果。
import random
def make_random_real():
num_list = []
for i in range(0, 10):
num_list.append(random.random())
return num_list
print(make_random_real())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.