Python的資料結構 元組

2022-03-04 21:59:57 字數 672 閱讀 4234

zoo = ('

大象','

老虎','

獅子','

北極熊'

)print('

the animal number of the is

', len(zoo))

print('

the animal of the zoo are

',zoo)

new_zoo = ('

孔雀','鱷魚'

,zoo)

print('

the new animal is

',new_zoo)

print('

the number of animal of the new zoo is

',len(new_zoo))

print('

the number 2 animal from the old zoo is

',new_zoo[2][2])

#就是乙個括號定義物件

#可以用len方法來找出物件

#可以格式化輸出,而且在格式化輸出的時候,如果有多個就是特別要用到元組

#還有在元組裡面新增元組,就變成多維陣列,特別是新增乙個的時候就變二維陣列,應該也是比較常用的,然後記住陣列的計數是從0開始的

2015/4/22 by kerita

python 資料結構 元組 tuple

字串 變數引用str s abc s abc 元組 如果這樣寫,就會是.t 123,abc come here t 123,abc come here 上面例子中看到的變數t,並沒有報錯,也沒有 最後乙個有效 而是將物件做為乙個新的資料型別 tuple 元組 賦值給了變數t。元組是用圓括號括起來的,...

Python之資料結構 元組

元組與列表的最大區別是列表可以修改 可以讀取 可以刪除,而元組建立之後則不能修改,但是可以刪除整個元組。1 定義元組 l1 1,2,3 print l1 print type l1 執行結果 如果元組只有乙個元素,則這個元素後面必須要有 否則元素就還是其原來的型別。l1 1,2,3 print l1...

Python中的資料結構 元組

元組是既定的,決定於建立的時候,所以不存在增刪改等一些操作。1.可變型別 2.不可變型別 a 1a 2 b 1print id 1 print id a print id b a和b都指向1的時候其位址相同,當a指向2的時候,a的位址變了,但是1本身是不變的 建立乙個元組 t 1,2,oop 4,2...