【发布时间】:2018-02-13 04:41:45
【问题描述】:
我有一些在 python 中创建函数的练习作业。其中一个输出月份列表。这是我的代码:
def outputlist(list):
for list_output in list:
print(list_output,end=" ")
return list_output
def main():
month = ["January", "February", "March", "April", "May", "June", "July", "August", "Setemper", "October", "November", "December"]
print("The list of the months of the year are:", outputlist(month))
main()
不知道为什么输出的句子没有按照顺序,应该是:
“一年中月份的列表是:一月二月三月四月五月六月七月八月九月十月十一月十二月”
但是,我得到的输出是:
January February March April May June July August September October November December 1. The list of the months of the year are: December
【问题讨论】:
-
你明白
print()和return的区别吗? -
你可以使用
print("The list of the months of the year are:", *month) -
@IgnacioVazquez-Abrams 我是python新手,所以我只知道“return”只会返回函数中的值
-
@JohnLaRooy 如果我使用那个,输出将如下所示 ['January', 'February', 'March', 'April', 'May', 'June', 'July' 、“八月”、“九月”、“十月”、“十一月”、“十二月”]。我不希望它显示 [] 和 ''
-
@VyQuangDao,确保你没有错过
*
标签: python-3.x printing output