Definition List
1 names = ["zhangyang"""Guyun "" Xiangpeng""xuliangchen"]
To take a value from a list by subscript
1 Print (Names[0], names[2])
Slices: Fetching multiple elements
1 Print(Names[1:3])#take the second to third value note: Gu Tou regardless of the end of the2 3 Print(Names[0:3])#take the first to the third value4 5 Print(Names[-1])#take the last value6 7 Print(Names[-2])#take the second-lowest value8 9 Print(Names[-3:-1])#take the third to the bottom of the last value note: From left to right valueTen One Print(names[-2:])#take the penultimate to the last value of the countdown Note: Omit the value after the colon, take the last A - Print(Names[:3])#take the first to third value note: Omit the value before the colon, and start with the first value - the Print(names[:])
Append Element
1 names.append ("leihaidong")
inserting elements
1 " Chenzhonghua " )2"xinzhiyu")
modifying elements
1 " Xiedi "
Delete Element
1 names.remove ("chenzhonghua") # method One 23 del names[1] # method Two 45 names.pop () # no subscript, the last one is deleted by default 6 7 names.pop (1) # method Three
Find Element
1 Print (Names.index ("xiedi")) 2 3 Print (Names[names.index ("xiedi")])
Statistical elements
1 Print (Names.count ("chenzhonghua"))
Clear List
1 names.clear ()
Reverse List
1 names.reverse ()
Sort List
1 names.sort ()
Python Learning Note "09" list, tuples