list = [4,2,6,9,8,7,1,5,3]
print(list[0:])
print(list[:-1])
print(list[5:])
print(list[:-3])
print(list[0:1])
print(list[1:-7])
print(list[-8:2])
print(list[::])
print(list[::1])
print(list[::2])
print(list[::3])
print(list[::-1])#if step<0 fetch the number from the right to the left, means 'reverse' here
print(list[::-2])
print(list[-2::-2])
The answer
[4, 2, 6, 9, 8, 7, 1, 5, 3]
[4, 2, 6, 9, 8, 7, 1, 5]
[7, 1, 5, 3]
[4, 2, 6, 9, 8, 7]
[4]
[2]
[2]
[4, 2, 6, 9, 8, 7, 1, 5, 3]
[4, 2, 6, 9, 8, 7, 1, 5, 3]
[4, 6, 8, 1, 3]
[4, 9, 1]
[3, 5, 1, 7, 8, 9, 6, 2, 4]
[3, 1, 8, 6, 4]
[5, 7, 9, 2]
简单的冒泡排序法练练手
# Bubble_sort
# 2018.5.24 in NEFU
n=10 # the number of the element of the list is n
list=list(range(n,0,-1))# the two 'list' is different !
for i in range(0,n-1):
for j in range(0,n-i-1):
if list[j] > list[j+1]:
list[j] , list[j+1] = list[j+1] , list[j]
print(list)
