‘’’
str()
int()
len()
list()
sorted()
print()
input()
enumerate()函数用于将一个可遍历的对象(如列表,元祖,或字符串)组合为一个索引序列
‘’’
l1=['a','abc','jk','opop']
for index,value in enumerate(l1):
print(index,value)
for index,value in enumerate('happy'):
print(index,value)
numbers=[5,7,8,9,2,0,6,4,9]
# numbers=sorted(numbers)
# print(numbers)
# numbers.sort()
#自定义排序方法
for i in range(len(numbers)):
for j in range (i+1,len(numbers)):
if numbers[i]>numbers[j]:#每次找出最小值放在前面
numbers[i],numbers[j]=numbers[j],numbers[i]
print(numbers)
代码
myList=[4,1,7,0]
for i in range(len(myList)-1):
for j in range(0,len(myList)-1-i):
if myList[j]>myList[j+1]:
tmp=myList[j]
myList[j]=myList[j+1]
myList[j+1]=tmp
print(myList)
‘’’
总结列表:
1.定义
l=[]空列表
l=[‘aaa’]
2.符号