The road to wudao-one day during the refining period (from the high ground in wanshu) and from the high ground in a heavy City
List some simple basic methods:
Example: A list
Usernames = ['Li si', 'wang 2', 'zhang san', 'machin']
Index: usernames [0] # Starts from 0 and ends from-1 (left to right)
Slice: usernames [] = ['wang 2'], that is, list [header: tail: Step Size], Gu header regardless of the end (left closed and right open), usernames [2:], from the third element to the last one
Partition assignment: usernames [1:] = ['ss'], that is, replacing the element whose subscript starts from 1,
# Len (usernames)-> List length, max (usernames), min (usernames), extreme values in the list
Add:
# Usernames. append ('marath') # append an element to the list: ['lily', 'wang 2', 'zhang san', 'machin', 'marath']
# Usernames. insert (index, content to be inserted), before the index !!
Delete:
# Del usernames [2], delete element # del is to delete variable
# Usernames. pop (INDEX). If no index is added, the last element is deleted by default.
# Usernames. remove (INDEX), in fact, slice can also be deleted
Change:
# Directly modify usernames [1] = 'mmmm', And the slice can also be modified.
Query:
# Usernames. index ('elemental) locate the position of an element in the list (index)
Others:
Usernames. count (element, start, end) calculates the number of times an element appears in the list (between start and end)
# Usernames. extend (['2', 33]), similar to list Splicing
Usenames. reserve () reverse list
Usernames. sort () sorting
Usernames. copy () or import copy. copy (usernames) shallow copy # reference
Import copy. deepcopy (usernames) Deep replication with caution (re-opening a memory)
Tuples: The elements are unchangeable ('ss', 'ddd ')
There are two ways to remember: index count