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); |
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
SN | Function with Description |
---|---|
1 | cmp(tuple1, tuple2) Compares elements of both tuples. |
2 | len(tuple) Gives the total length of the tuple. |
3 | max(tuple) Returns item from the tuple with max value. |
4 | min(tuple) Returns item from the tuple with min value. |
5 | tuple(seq) Converts a list into tuple. |