编写高质量Python代码总结:待完成

1:字符串格式化

#避免%过多影响阅读
print('hello %(name)s'%{'name':'tom'})
#format方法
print('{name} is very {emmition}'.format(name='egon',emmition='happy'))

2:字符串切分

#将字符串转换为列表
a='12345' res=list(reversed(a)) print(res)

 3:三元表达式

#替代之前版本中 C?X:Y
print X if X>Y else Y

 4:注释

#行注释要和代码间隔一定注释

#块级注释中注释和代码间隔数行

5:

原文地址:https://www.cnblogs.com/xuechengeng/p/10300952.html