11 2011 档案

摘要:一 要写出容易读的程序,应该使用什么样的风格(idioms)读 the python cookbook ,尤其是前几章。那里有优秀的python风格的代码。Build strings as a list and use ''.join at the end 。join是由分隔符调用的字符串方法,而不是由list调用的。可以使用空串作为连接符来调用join方法,这是python比较怪异的地方。之所以如此,是因为,使用“+”操作符消耗的时间二次的而不是线性的。Wrong: for s in strings: result += sRight: result = '' 阅读全文
posted @ 2011-11-06 15:12 macula7 阅读(624) 评论(0) 推荐(0)