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

How to use list in Python 2-2

編輯:Python

1 modify List The value of the element in

stay Python in List How to use 2-1_hou09tian The blog of -CSDN Blog

I mentioned , It can be accessed by index “ list ” The elements in . therefore , Can be modified by index “ list ” The value of the element in , Pictured 1 Shown .

chart 1 modify “ list ” The value of the element

  among ,squares[3] Express “ list ”squares Fourth element in , The initial value of this element is 16, The modified value changes to 10.

It can also be modified by interval index “ list ” The value of the element in , Pictured 2 Shown .

chart 2 Modify by interval indexing “ list ” The value of the element in

  among ,squares[2:4] Express squares The third and fourth elements in .

2 Additive elements

adopt “ list ” Variable call append() Function to “ list ” Additive elements , Pictured 3 Shown .

chart 3  Additive elements

  among ,squares.append(36) It means that you will “36” Add to squares Tail of .

3 Remove elements

You can use as shown in the figure 4 Delete as shown in “ list ” Data in .

chart 4 Delete “ list ” The elements in

 4 obtain “ list ” The number of elements in

adopt len() Function to obtain “ list ” The number of elements in , Pictured 5 Shown .

chart 5 obtain “ list ” The number of elements in

  among ,len() The arguments to the function are specified “ list ” Variable , The return value is the “ list ” The number of elements in the variable .


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