13719654321 发表于 2017-4-30 11:37:51

Python Native Datatypes -- tuple

>>>t=( " a " ," b " ," mpilgrim " ," z " ," example " )
>>>t
( ' a ' ,' b ' ,' mpilgrim ' ,' z ' ,' example ' )
>>>t
' a '
>>>t[− 1 ]
' example '
>>>t[ 1 : 3 ]
( ' b ' ,' mpilgrim ' )
   1、tuple没有任何方法
2、tuple和list可以相互转化
4、


Common tuple literals and operations
Operation
Interpretation


( )




An empty tuple





t1 = (0,)




A one-item tuple (not an expression)





t2 = (0, 'Ni', 1.2, 3)




A four-item tuple





t2 = 0, 'Ni', 1.2, 3




Another four-item tuple (same as prior line)





t3 = ('abc', ('def', 'ghi'))




Nested tuples





t1t3t1len(t1)




Index, slice, length





t1 + t2t2 * 3




Concatenate, repeat





for x in t23 in t2




Iteration, members


  
tuple这些操作和list非常之象。。
页: [1]
查看完整版本: Python Native Datatypes -- tuple