python--以1-31的数字作为结尾的列表?论英文好的重要性!

本文介绍了一个巧妙的方法来构造Python列表,以实现打印1到31日期的英文缩写形式,并解释了列表推导式的原理及如何利用字符串进行列表构建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、python基础教程第2板(修订版)【代码清单2-1】中有一段要求打印‘以1-31的数字作为结尾的列表’  
  截取代码示例:
endings =['st','nd','rd'] +17*['th'] + ['st','nd','rd'] +7*['th'] +['st']
  运行结果:print(endings)
    ['st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st']
注:以上测试结果在Pycharm完成

   二、刚一开始疑虑为何列表可以那样写?稍加揣摩并Baidu了下,原来是英文的1-31天的英文末尾字符的简写,其中1-31天的英文对照如下:

   first (1st) 
   second (2nd) 
   third (3rd) 
   fourth (4th) 
   fifth (5th) 
   sixth (6th) 
   seventh (7th) 
   eighth (8th) 
   ninth (9th) 
   tenth (10th) 
   eleventh (11th) 
   twelfth (12th) 
   thirteenth (13th) 
   fourteenth (14th) 
   fifteenth (15th) 
   sixteenth (16th) 
   seventeenth (17th) 
   eighteenth (18th) 
   nineteenth (19th) 
   twentith(20th)
   twenty-first(21st)
   twenty-second(22nd)
   twenty-third(23rd)
   twenty-fourth(24th)
   twenty-fifth(25th)
   twenty-sixth(26th)
   twenty-seventh(27th)
   twenty-eighth(28th)
   twenty-ninth(29th)
   thirtith(30th)
   thirty-first(31st)

 三、由此可以看出英语在日常编码和学习的重要性,坚持编码的过程也要坚持学习English!

转载于:https://www.cnblogs.com/apff/p/7436611.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值