Python Medium List yes “ list ” It means , It can be regarded as a combination of arrays of the same type or different types , Generally speaking, I will “ list ” As a combination of the same type of data .
Definition “ list ” The method is shown in the figure 1 Shown .
chart 1 Definition “ list ”
among , Variable squares The type of is list . A list variable consists of square brackets and the values in it , The values in square brackets are separated by commas .
stay Python How to use strings in 2-2_hou09tian The blog of -CSDN Blog
I mentioned , You can use an index in a string to access characters or substrings in the string , stay “ list ” You can also use indexes to access “ list ” Single or multiple elements in , Pictured 2 Shown .
chart 2 stay “ list ” Use index
among ,squares[0] Represents a list variable squares The first element of ;squares[-1] Represents a list variable squares Last element of ;squares[-3:] Represents a list variable squares From the penultimate element to the last element of .
have access to “+” Multiple “ list ” Combine into one “ list ”, Pictured 3 Shown .
chart 3 “ list ” The combination of
among ,squares1 Is newly defined “ list ”, adopt “+” take squares and squares1 Two “ list ” Merge into a list .