The Zen of Python, by Tim Peters Beautiful is better than ugly. 优美胜于丑陋 Explicit is better than implicit. 明了胜于晦涩 Simple is better than complex. 简单胜过复杂 Complex is better than complicated. 复杂胜过凌乱 Flat is better than nested. 扁平胜于嵌套 Sparse is better than dense. 间隔胜于紧凑
a = 5 # 可以这样 print(2 < a < 10) # 也可以这样 print(10 > a <= 9)
True True
a = 2 b = 3 print(a, b) # 直接交换 a, b = b, a print(a, b)
2 3 3 2
a = ['a', 'b', 'c', 'd', 'e'] for(int i = 0; i < len(a); i++): print(a[i])
a = ['a', 'b', 'c', 'd', 'e'] # 对a的长度使用range生成一个序列,然后遍历 for i in range(len(a)): print(a[i])
a b c d e
a = ['a', 'b', 'c', 'd', 'e'] # 对a的长度使用range生成一个序列,然后遍历 for i in enumerate(a): print(i) # 或者这样 for index, value in enumerate(a): print(index, value)
(0, 'a') (1, 'b') (2, 'c') (3, 'd') (4, 'e') 0 a 1 b 2 c 3 d 4 e
for i in foo:
if i == 0:
break
else:
print("i was never 0")
# 对每一个规则使用引号括起来
pattern = (
"^" # beginning of string
"M{0,4}" # thousands - 0 to 4 M's
"(CM|CD|D?C{0,3})" # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),
# or 500-800 (D, followed by 0 to 3 C's)
"(XC|XL|L?X{0,3})" # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's),
# or 50-80 (L, followed by 0 to 3 X's)
"(IX|IV|V?I{0,3})" # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),
# or 5-8 (V, followed by 0 to 3 I's)
"$" # end of string
)
print(pattern)
# 然后bapattern放入对应的re匹配方法中。
^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$
def seek_next_line(f): for c in iter(lambda: f.read(1),'\n'): pass
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有