|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1、元组的创建
一般情况下你用逗号分隔了一些值,你就自动创建了元组,
如:
>>> "x",
('x',)
2、什么时候创建一个元组,必须逗号和小括号同时存在呢??在拼接只有一个元素的元组的时候
- >>> temp=1,2,3,4,5
- >>> temp
- (1, 2, 3, 4, 5)
- >>> temp=temp[:2]+7,+temp[2:]
- Traceback (most recent call last):
- File "<pyshell#15>", line 1, in <module>
- temp=temp[:2]+7,+temp[2:]
- TypeError: can only concatenate tuple (not "int") to tuple
- >>> temp=temp[:2]+(7,)+temp[2:]
- >>> temp
- (1, 2, 7, 3, 4, 5)
复制代码
3、元组的方法
1、count()
计算并返回指定元素的数量
2、index()
寻找并返回指定参数的索引值
|
评分
-
查看全部评分
|