程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to use list in Python 2-1

編輯:Python

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 .

1 Definition

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 .

2 Use index

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 .

3 Multiple “ list ” The combination 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 .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved