luyantl 发表于 2018-8-30 23:55:47

元组,戴上了枷锁的列表

>>> print('元组,戴上了枷锁的列表')
元组,戴上了枷锁的列表
>>> print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>>> tuple1=(1,2,3,4,5,7,6)
>>> tuple1
2
>>> tuple1
(7, 6)
>>> tuple1[:]
(1, 2, 3, 4, 5, 7, 6)
>>> tuple1=9
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
    tuple1=9
TypeError: 'tuple' object does not support item assignment
>>> temp=(1)
>>> temp
1
>>> type(temp)
<class 'int'>
>>> type(tuple1)
<class 'tuple'>
>>> temp2=1,2,3,4,
>>> type(temp2)
<class 'tuple'>
>>> temp=(1,)
>>> type(temp)
<class 'tuple'>
>>> temp3=2,4,2,3,4
>>> type(temp3)
<class 'tuple'>
>>> print('元组中,逗号是关键')
元组中,逗号是关键
>>> 3*5
15
>>> 3*5,
(15,)
>>> 3*(5)
15
>>> 3*(5,)
(5, 5, 5)
>>> temp=('小甲鱼','黑夜','迷途')
>>> temp.insert(2.'怡静')
SyntaxError: invalid syntax
>>> temp.insert(2,'怡静')
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
    temp.insert(2,'怡静')
AttributeError: 'tuple' object has no attribute 'insert'
>>> print('哪些操作符可以用在元组上,')
哪些操作符可以用在元组上,
>>>
页: [1]
查看完整版本: 元组,戴上了枷锁的列表