定义方法:
# 选择排序
def sort2(list2):
for i in range(0,len(list2)-1):
temp = i
for j in range(i+1,len(list2)):
if list2[temp] > list2[j]:
temp = j
list2[temp],list2[i] = list2[i],list2[temp]
return list2
调用方法:
from sort2 import sort2
if __name__ == '__main__':
list2 = [3,7,4,6,8,2]
sort2(list2)
print('输出的数组:')
for k in sort2(list2):
print(k)