枚举 不要这么做: 全选复制放进笔记 i = 0 for item in iterable: print i, item i += 1 而是这样: 全选复制放进笔记 for i, item in enumerate(iterable): print i, item Enumerate可以接受第二个参数,例如: 全选复制放进笔记 >>> list(enumerate('abc')) [(0, 'a'), (1, 'b'), (2, 'c')] >>> list(enume…
枚举 不要这么做: i = 0 for item in iterable: print i, item i += 1 而是这样: for i, item in enumerate(iterable): print i, item enumerate可以接受第二个参数,例如: >>> list(enumerate('abc')) [(0, 'a'), (1, 'b'), (2, 'c')] >>> list(enumerate('abc', 1)) [(1, 'a'),…
python出输出字符串方式: >>> who='knights' >>> what='NI' >>> print ('we are the',who,'wha say',what,what,what,what) we are the knights wha say NI NI NI NI >>> print ('we are the %s who say %s'% (who,(what+' ')*4)) we are the kni…