Python索引示例
#根据给定的年月日以数字形式打印出日期
months = [‘Juanuary’,’February’,’March’,’April’,’May’,’June’,’July’,’Aygust’,
‘September’,’October’,’November’,’December’]
#以1-31的数字作为结尾的列表
endings = [‘st’,’nd’,’rd’]+17*[‘th’]\
+[‘st’,’nd’,’rd’]+7*[‘th’]\
+[‘st’]
#提示用户输入年月日
year = input(‘Year: ‘)
month = input(‘Month (1-12): ‘)
day = input(‘Day (1-31): ‘)
month_number = int(month)
day_number = int(day)
#将月份和天数减1,以获得正确的索引
month_name = months[month_number-1]
ordinal = day + endings[day_number-1]
print (month_name + ‘ ‘ + ordinal + ‘, ‘ + year)
转载自:https://blog.csdn.net/tianyi_6677/article/details/79252166