1、用 ...and ... or ... 来替换 if....else...
old:if flag:
print 'yes'
else:
print 'no'
new:print flag and 'yes' or 'no'
2、经常被字符串里面很多的%s搞糊涂?还不快试一下Template
old:message = '%s is better than %s,and %s is worse than %s.so,%s is better than %s'
print message %('a','b','c','b','a','c')
new:from string import Template
message = Template( '$a is better than $b,and $c is worse than $b.so,$a is better than $c')
print message.substitute(a='a',b='b',c='c')
没有评论:
发表评论