Python中的tuple

1.空的tuple:     tup1 = ();

2.只含有一个元素的tuple:

tup1 = (50,); #注意,必须有,尽管只有一个元素


3Delete Tuple Elements:

Removing individual tuple elements is not possible. There is, of course, nothing wrong with putting together another tuple with the undesired elements discarded.

To explicitly remove an entire tuple, just use the del statement:

Example:

tup = ('physics', 'chemistry', 1997, 2000);

print (tup);
del tup;
print ("After deleting tup : ")
print (tup);

This will produce following result. Note an exception raised, this is because after del tup tuple does not exist any more:

('physics', 'chemistry', 1997, 2000) After deleting tup : Traceback (most recent call last): File "test.py", line 9, in <module> print tup; NameError: name 'tup' is not defined

 

 

相关函数:

Python includes following tuple functions

SNFunction with Description
1cmp(tuple1, tuple2)
Compares elements of both tuples.
2len(tuple)
Gives the total length of the tuple.
3max(tuple)
Returns item from the tuple with max value.
4min(tuple)
Returns item from the tuple with min value.
5tuple(seq)
Converts a list into tuple.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值