Python learning notes (1) -- list, python learning Notes list
In python, List is a set of ordered elements included in square brackets.
Li = ["a", "B", "mpilgrim", "z", "example"]
Index
List is ordered and divided into forward (from left to right) and reverse (from right to left). The first element of any non-empty List is always List [0]. the last element of the list that contains n elements in the forward direction is List [n-1], because list starts from 0. The first element of any non-empty List in reverse order is List [-1], and the positive and negative conversion relationship is List [n] = List [len (List)-n].
Slice
In general, it is [start position: end position: Step Size]. Because the end position is not included, you need to push it back, for example, if the first two elements are used, they are [0: 2] and the values of [0] and [1] are obtained.
Add
Append, insert, and extend can be used to add elements. The main differences are:
List. append (element): append an element to the end of the List.
List. insert (location, element): insert an element at a location
List. extend (list): extend is used to connect two lists. Extend only accepts one parameter. this parameter is always list and each element in this list is added to the original List.