def cool():
if (user wants to receive one element):
return 10
if (user wants to receice two elements):
return 4, 2
a = cool()
print(a) # 10
x, y = cool()
print(x) # 4
print(y) # 2
def cool():
if (user wants to receive one element):
return [10]
if (user wants to receice two elements):
return [4, 2]
a = cool()
for value in a:
print(value)
#or just
print(a)
#if you want everything to print on one line:
outputString = ""
for value in a:
outputString += str(value) + " "
#might have to do outputString = outputString + str(value) + " "
print(outputString)
可以将其作为参数传递给函数
可以使用数组
您可以使用一个列表并将其拼接起来来完成此操作。下面的函数获取一个列表,并在用户返回计数时对其进行切片
输出
相关问题 更多 >
编程相关推荐