def get_date(date):
month = date[4:7]
if month == "01":
month_string = "January"
elif month == "02":
month_string = "February"
elif month == "03":
month_string = "March"
elif month == "04":
month_string = "April"
elif month == "05":
month_string = "May"
elif month == "06":
month_string = "June"
elif month == "07":
month_string = "July"
elif month == "08":
month_string = "August"
elif month == "09":
month_string = "September"
elif month == "10":
month_string = "October"
elif month == "11":
month_string = "November"
elif month == "12":
month_string = "December"
return month_string
变量“日期”是格式为 yyyy/mm/dd 的输入字符串。
此函数测试输入 yyyy/mm/dd 中的月份是否是这些数字之一,并为该数字值分配一个字符串。这个决策结构不应该给month_string赋值吗?我不明白为什么不是。