三,列表(list)
格式:[元素,元素, , ,]
car = ["F1","bmw","ford","amg"]
print(car)
# 取数据 列表名[序号] 从0开始数
print("my frist car is "+car[0])
# 添加元素 append("添加内容")
car.append("红旗")
print(car)
# 插入元素 insert(位置,"元素")
car.insert(2,"红旗")
print(car)
#添加列表 extend
a = [ "A","B","C" ]
b = [1,2,3]
a.extend(b)#a后面添加一个列表
print(a)
>>>["A","B","C",1,2,3]
print(a[0:3:0])#从索引0到3,每隔2个取一个
>>>"A" "C'
print(len(a))#len 计算列表长度 即数据个数
>>>5
i = ['adsdas','sdsa',a,2,]
print(len(i))
print(len(i[0]))
>>>4
>>>6
#倒叙 reserve
j = [ 1,2,3]
j.reserve()
print(j)
>>>[3,2,1]
#从小到大排列 sort
k = [3,1,54,21]
k.sort()
print(k)
>>>[1,3,21,54]