python基礎學習二 資料結構之list及相關基本操作

來源:互聯網
上載者:User

標籤:相關   學習   更改   highlight   集合   python   資料集   bsp   pop   

list是py內建的一種資料類型,list就是列表的意思,list就是一種有序的資料集合,可以隨時增加和刪除list的元素。

生活中,比如我們要列出全班同學的名字,就可以用list來表示

>>> classmate = [‘大逗比‘, ‘小豆比‘]>>> classmate[‘大逗比‘, ‘小豆比‘]

  

這個時候,classnamte就是一個list

 

list的訪問可以用:

list[0]  list[1]

或者:

list[-1]  list[-2]

 

list的操作方法:

append 追加元素到list的末尾,如:classmate.append(‘小小豆‘)  

insert追加到指定位置,如:classmate.insert(1,‘大大逗比‘)

pop刪除list末尾元素,如:classmate.pop()

如果要刪除指定的元素,如:classmate.pop(1)

更改元素:

classmate[1] = ‘不是逗比‘

 

python基礎學習二 資料結構之list及相關基本操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.