【发布时间】:2018-02-20 02:31:40
【问题描述】:
我正在尝试在 python 3 中将日期(即 6/15/2000)转换为日期、月份缩写和年份(即 2000 年 6 月 15 日)
def main():
dateStr = raw_input("Enter a date (mm/dd/yyyy): ")
monthStr, dayStr, yearStr = string.split(dateStr, "/")
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
monthStr = months[int(monthStr)–1]
main()
【问题讨论】:
-
你在学习哪个 Python 教程?该教程是为哪个版本的 Python 设计的?这是否与您使用的 Python 版本相匹配?
-
告诉我们错误消息的确切措辞是什么,以及产生它的代码行。stackoverflow.com/help/mcve
-
int(monthStr)–1中的–不是减号而是破折号,替换为-。如果您发布了错误,它会更容易提供帮助。 (另外raw_input()不在 Python 3 中)
标签: python python-3.x