鱼C论坛

 找回密码
 立即注册
查看: 2675|回复: 0

[学习笔记] 元组,戴上了枷锁的列表

[复制链接]
发表于 2018-8-30 23:55:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
>>> print('元组,戴上了枷锁的列表')
元组,戴上了枷锁的列表
>>> print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>>> tuple1=(1,2,3,4,5,7,6)
>>> tuple1[1]
2
>>> tuple1[5:]
(7, 6)
>>> tuple1[:]
(1, 2, 3, 4, 5, 7, 6)
>>> tuple1[0]=9
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    tuple1[0]=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('哪些操作符可以用在元组上,')
哪些操作符可以用在元组上,
>>>
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-22 07:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表