關於元組,元組和列表之間的轉換

注意元組是小括號,而且元祖只有兩個功能count和index

>>> t=(1,2,3,4)

>>> dir(t)

['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']

>>> 


元祖轉換成列表

>>> type(t)

<type 'tuple'>

>>> a=list(t)

>>> type(a)

<type 'list'>


列表轉換成元祖

>>> a

[1, 2, 3, 4]

>>> type(a)

<type 'list'>

>>> t=tuple(a)

>>> t

(1, 2, 3, 4)

>>> type(t)

<type 'tuple'>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章