#Bad import urllib.request url = r'http://www.landsblog.com' req = urllib.request.Request(url) response = urllib.request.urlopen(req) #Good form urllib import request url = r'http://www.landsblog.com' req = request.Request(url) response = request.urlopen(req)
from module_a import fun as a_fun from module_b import fun as b_fun
from bs4 import BeautifulSoup as BS html = ''' <html> ...... </html> ''' soup = BS(html)
>>> 1 + 1 2 >>> _ 2
# Bad string = ['a','b','c','d','e','f','g','h'] def fun(string): all_string = '' for i in string: all_string += i return all_string # Good string = ['a','b','c','d','e','f','g,'h'] def fun(string): all_string = ''.join(string) return all_string
# Bad a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] re_a = [[row[col] for row in a] for col in range(len(a))] >>> [[1, 4, 7], [2, 5, 8], [3, 6, 9]] # Good a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] re_a = list(zip(*a)) >>> [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
# Bad
a = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
def reverse_dict(a):
new_dict = {}
for k,v in m.items():
new_dict[v] = k
return new_dict
# Good
a = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
def reverse_dict(a):
k = a.keys()
v = a.values()
new_dict = dict(zip(v, k))
return new_dict
a = [1, 2, 3, 4, 5, 6] list(zip( a[::2], a[1::2] )) >>> [(1, 2), (3, 4), (5, 6)]
# Bad tmp = a a = b b = tmp #Good a, b = b, a
a = [8, 23, 45, 12, 78] for index, value in enumerate(a): print(index , value)
try: pass except (ExceptionA,ExceptionB,.....) as e: pass
a = [1, 2, 3, 4, 5, 6] list(zip( *[iter(a)]*2 )) >>> [(1, 2), (3, 4), (5, 6)]
a = ['a', 'b', 'c', 'd', 'e', 'f'] a_i = a.index(a) >>> 0
#Bad a = 'Python is a powerful languange.' list_a = list(a) list_a.reverse() re_a = ''.join(list_a) #Good a = 'Python is a powerful languange.' re_a = a[::-1][b]11.数值比较[/b]
x = 2 if 1< x <3: print(x) >>> 2 if 1< x >0: print(x) >>> 2
with open('nothing.txt','r') as f:
f.read()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有