Home > Backend Development > Python Tutorial > Python交换变量

Python交换变量

WBOY
Release: 2016-06-16 08:47:39
Original
1327 people have browsed it

如:

复制代码 代码如下:

a, b, c = b, c, a

来个复杂一点的例子,再来一顿家喻户晓的“冒泡排序”吧:
复制代码 代码如下:

array = [1, 2, 5, 3, 6, 8, 4]
for i in range(len(array) - 1, 1, -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

好吧,今天就吃到这里了,请密切关注,以后还有更多美味大餐等着您呢!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template