标签:style color 使用 for ar line python file
赋值:
a, b, c = ‘xixi‘, ‘haha‘, ‘hehe‘
连接字典:
>>> s = {1:‘a‘, 2:‘b‘, 3:‘c‘}
>>> s.keys()
[1, 2, 3]
>>> s.values()
[‘a‘, ‘b‘, ‘c‘]
>>> s.items()
[(1, ‘a‘), (2, ‘b‘), (3, ‘c‘)]
>>> [(k, v) for (k, v) in s.items()]
[(1, ‘a‘), (2, ‘b‘), (3, ‘c‘)]
>>> [(k:v) for (k, v) in s.items()]
File "<stdin>", line 1
[(k:v) for (k, v) in s.items()]
^
SyntaxError: invalid syntax
>>> [‘%d:%s‘%(k, v) for (k, v) in s.items()]
[‘1:a‘, ‘2:b‘, ‘3:c‘]
>>> ‘,‘.join([(‘%d:%s‘)%(k, v) for (k, v) in s.items()])
‘1:a,2:b,3:c‘
使用 if 0<i<10:, 比if i>0 and i<10: 性能要好
标签:style color 使用 for ar line python file
原文地址:http://www.cnblogs.com/freemao/p/3884125.html