while i < len(str): print str[i]
每次循环迭代都要运行len()这个函数,所以可改为如下提高效率:
length = len(str) while i < length: print str[i]