Tuple definition: Use parentheses to enclose elements separated by commas; empty parentheses denote empty tuples; when there is only one element, you must end with a comma.
Basic operation of the sequence:
Len ()--to find the length of the sequence
such as a string "a= ' Qweqerq '", its length can be thought
*--Repeating sequence elements
For example, repeat printing 20 "#" can be expressed as
In [5]: "#" * 20Out[5]: ‘####################‘In [7]: a * 5Out[7]: ‘qweqerqqweqerqqweqerqqweqerqqweqerq‘
in--determines whether the element is in sequence
For example, determine if a is in sequence a, if present, return "True", not present, return "False"
In [2]: a=‘qweqerq‘In [8]: "a" in aOut[8]: FalseIn [9]: "q" in aOut[9]: TrueIn [10]: "a" not in aOut[10]: True #a不在序列a里面,为真
Max ()--Returns the maximum value
In [11]: max(a)Out[11]: ‘w‘
Min ()--Returns the minimum value
In [12]: min(a)Out[12]: ‘e‘
CMP (x, y)--compare two sequences for equality
In [13]: a=12345In [14]: cmp(a,1234)Out[14]: 1 #表示前者比后者多In [15]: cmp(a,12345)Out[15]: 0 #表示两者相等In [16]: cmp(a,123456)Out[16]: -1 #表示前者比后者少
Tuples and lists are very similar, tuples and strings are immutable, and you can store a range of values, usually when a user-defined function can safely take a set of values, that is, the value of the tuple being used does not change.
In [17]: t1=1In [18]: type(t1)Out[18]: int #表示的是字符串In [19]: t2=1,In [20]: type(t2)Out[20]: tuple #表示的是元组
Sequences and tuples are similar in operation
In [21]: t=(a,"b","c") #a未加引号,表示变量In [22]: tOut[22]: (12345, ‘b‘, ‘c‘) #显示a的实际代表的值In [24]: b="qwe"In [25]: t=("a",b,"c")In [26]: tOut[26]: (‘a‘, ‘qwe‘, ‘c‘)
In Python, everything can be called an object.
Python tuple ()