首页 > 编程语言 > 详细

Python 效率

时间:2015-12-02 14:21:42      阅读:376      评论:0      收藏:0      [点我收藏+]
while i < len(myString):
    print character %d is:%myString[i]


length = len(myString)

while i < length:
    print character %d is:%myString[i]


for otherchar in myInput[1:]:
    if otherchar not in alphas + nums:


alphnums = alphas + nums
for otherchar in myInput[1:]:
    if otherchar not in alphnums:

如果在循环里面使用len则会导致多次调用len函数会导致效率低下

 

如果not in alphas + nums 则每次判断都会进行加法 也会导致效率低下

Python 效率

原文:http://www.cnblogs.com/magicpower/p/5012816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!