python學習之資料類型—元組tuple

來源:互聯網
上載者:User

標籤:pyc   資料類型   view   for   逗號   增加   python   har   迴圈   

元組:tuple

1、python四大不可變資料類型之一(int,str,tuple,bool)

2、以小括弧包起來起來,如只有一個元素,需在尾部加一個逗號,因為不加的話,python可能認為其實一個變數或是做數學運算等

3、元組中的第一層資料不可變,如其第二層資料類型為可變資料類型(list,dict,set),其可變

4、元組可通過迴圈,切片等進行查詢

5、元組是有序的

增:

??元組不可變,故無法增加元素

刪:

?? 同上

改:

??同上

查:

索引和切片查詢:

tuple_staudy = ("alter","china","upper","lower","iterable",[‘pycharm‘,‘file‘,‘edit‘,‘view‘])

tuple_staudy [3]    ---->lower

tuple_staudy[1:5]  ----->china,upper,lower,iterable

for 迴圈尋找:

for i in tuple_staudy:

  print(i)

解構:

a,b = ("3","6")

print(a)    a = 3

print(b)    b = 6

註:左邊元素個數必須和右邊一致,同樣的str,list,dict  都有這種特性

如 str , list ,tuple 公用方法  count(對象), len(對象) ,index(”元素“)

 

python學習之資料類型—元組tuple

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.