当前位置: 技术问答>linux和unix
linux 中的endings
来源: 互联网 发布时间:2017-03-19
本文导语: months=[ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'N...
months=[
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]
endings=['st','nd','rd']+17*['th']
+['st','nd','rd']+7*['th']
+['st']
year=raw_input('Year: ')
month=raw_input('Month(1-12): ')
day=raw_input('Day(1-31): ')
month_number=int(month)
day_number=int(day)
month_name=months[month_number-1]
ordinal=day+endings[day_number-1]
print month_name + ' ' + ordinal + ' ' + year
我是新手,最近迷上python,我不明白endings和ordinal是什么,是不是库函数,还有python可以单步调式吗?怎么操作呢?谢谢大家了。
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]
endings=['st','nd','rd']+17*['th']
+['st','nd','rd']+7*['th']
+['st']
year=raw_input('Year: ')
month=raw_input('Month(1-12): ')
day=raw_input('Day(1-31): ')
month_number=int(month)
day_number=int(day)
month_name=months[month_number-1]
ordinal=day+endings[day_number-1]
print month_name + ' ' + ordinal + ' ' + year
我是新手,最近迷上python,我不明白endings和ordinal是什么,是不是库函数,还有python可以单步调式吗?怎么操作呢?谢谢大家了。
|
从你贴的东西来回答你,endings和ordinal是两个变量,当然可以单步调试。
如果你用eclipse+pydev、或者eric+pyqt或者ulipad调试起来会比较爽一些。
用自带的idle也可以调试,就是土了些,先用idle打开你的脚本文件,然后f5运行,会调出python shell,在这个窗口中debug菜单选中debugger,再切换会原来窗口再运行就可以单步运行了。
如果你用eclipse+pydev、或者eric+pyqt或者ulipad调试起来会比较爽一些。
用自带的idle也可以调试,就是土了些,先用idle打开你的脚本文件,然后f5运行,会调出python shell,在这个窗口中debug菜单选中debugger,再切换会原来窗口再运行就可以单步运行了。
|
你还不如迷上Php.
|
刚好我今天也在看这行代码,endings是定义的一个变量,后面ordinal会调用这个变量,我在
endings=['st','nd','rd']+17*['th']
+['st','nd','rd']+7*['th']
+['st']
这行纠结了好久,始终不明白为什么后面会有个17*和7* ,百度了一下,看了一位仁兄的答案,终于明白了,原来该变量定义的是1-31这31个数的英文后缀,这31个数的英文是1:first2:second3:third4:fourth5:fifth6:sixth7:seventh8:eighth9:ninth10:tenth11:eleventh12:twelfth13:thirteenth14:fourteenth15:fifteenth16:sixteenth17:seventeenth18:eighteenth19:ninteenth20:twentieth21:twentyfirst22:twenty-second23:twenty-third24:twenty-fourth25:twenty-fifth26:twenty-sixth27;twenty-seventh28:twenty-eighth29:twenty-ninth30:thirtieth31:thirty-first
其中在第一个 ['st','nd','rd']后面从fourth到twentieth一共是17个‘th’,然后是又一个['st','nd','rd']后面再从twenty-fourth到thirtieth一共是7个‘th’,纠结了好久哇,原来这么简单
endings=['st','nd','rd']+17*['th']
+['st','nd','rd']+7*['th']
+['st']
这行纠结了好久,始终不明白为什么后面会有个17*和7* ,百度了一下,看了一位仁兄的答案,终于明白了,原来该变量定义的是1-31这31个数的英文后缀,这31个数的英文是1:first2:second3:third4:fourth5:fifth6:sixth7:seventh8:eighth9:ninth10:tenth11:eleventh12:twelfth13:thirteenth14:fourteenth15:fifteenth16:sixteenth17:seventeenth18:eighteenth19:ninteenth20:twentieth21:twentyfirst22:twenty-second23:twenty-third24:twenty-fourth25:twenty-fifth26:twenty-sixth27;twenty-seventh28:twenty-eighth29:twenty-ninth30:thirtieth31:thirty-first
其中在第一个 ['st','nd','rd']后面从fourth到twentieth一共是17个‘th’,然后是又一个['st','nd','rd']后面再从twenty-fourth到thirtieth一共是7个‘th’,纠结了好久哇,原来这么简单