【问题标题】:How do I add a full-stop at the end of this printed list?如何在此打印列表的末尾添加句号?
【发布时间】:2019-11-13 01:06:17
【问题描述】:
start_year = int(input("Enter start year:"))
end_year = int(input("Enter end year:"))

mylist = []

for year in range(start_year,end_year):
    if ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0):
        mylist.append(int(year))


for i in range(0, len(mylist), 10):
    print(*mylist[i:i+10], sep=', ')

【问题讨论】:

  • 你想要类似:2000, 2004, . ?

标签: python list punctuation


【解决方案1】:

print 函数的end 参数从其默认值'\n' 更改。文档:https://docs.python.org/3/library/functions.html#print

试试这个:

print(*mylist[i:i+10], sep=', ', end='.\n')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多