Python天天美味(1) - 交换变量

    Python美味第一顿,来个方便快捷的变量交换!为什么是Python?!因为Python中交换变量不需要临时变量!如:
   
a, b, c = b, c, a
 
    来个复杂一点的例子,再来一顿家喻户晓的“冒泡排序”吧:
   
array = [1253684]
for i in range(len(array) - 11-1):
    
for j in range(0, i):
        
if array[j] > array[j + 1]:
            array[j], array[j 
+ 1= array[j + 1], array[j]
print array

    好吧,今天就吃到这里了,请密切关注,以后还有更多美味大餐等着您呢!

 

Python天天美味系列(总)

Python 天天美味(1) - 交换变量

Python 天天美味(2) - 字符遍历的艺术  

Python 天天美味(3) - 字符转换  

Python 天天美味(4) - isinstance判断对象类型 

Python 天天美味(5) - ljust rjust center 

...

 

posted @ 2008-04-29 22:01  CoderZh  阅读(7552)  评论(14编辑  收藏  举报