列表
列表(打了激素的数组):可以存取任意数据类型
列表中可以存取列表
service = ["https","ftp","ssh"]
print(service[0])
print(service[-1])
print(service[::-1])
print(service[1:])
print(service[:-1])
print(service * 3)
servicel = ["mysql"+"python"]
print(service+servicel)
print("mysql" in servicel)
print("mysql" not in servicel)
https
ssh
['ssh', 'ftp', 'https']
['ftp', 'ssh']
['https', 'ftp']
['https', 'ftp', 'ssh', 'https', 'ftp', 'ssh', 'https', 'ftp', 'ssh']
['https', 'ftp', 'ssh', 'mysqlpython']
False
True
service = ["https","ftp","ssh"]
service.append("fileallld")
print(service)
service.append(['mysql','index'])
print(service)
service.insert(1,'hh')
print(service)
['https', 'ftp', 'ssh', 'fileallld']
['https', 'ftp', 'ssh', 'fileallld', ['mysql', 'index']]
['https', 'hh', 'ftp', 'ssh', 'fileallld', ['mysql', 'index']]
列表.pop
列表.remove
del 列表[下标]
列表.count("元素")
列表.index("元素")
列表.sort()
列表.sort(reverse=Ture)
列表.shuffle
列表也可以通过索引值来赋值
service = ["https","ftp","ssh"]
service[0] = 'sa'
print(service)
print(service[:2])
service[:2] = ["ab","hk"]
print(service)
['sa', 'ftp', 'ssh']
['sa', 'ftp']
['ab', 'hk', 'ssh']
|