两点水
This commit is contained in:
@@ -25,9 +25,10 @@ tuple3=()
|
||||
tuple4=(123,)
|
||||
```
|
||||
|
||||
如果不加逗号,创建出来的就不是 tuple (元组),而是指 ```123``` 这个数了,这是因为括号 ()既可以表示 tuple,又可以表示数学公式中的小括号,这就产生了歧义,因此,Python 规定,这种情况下,按小括号进行计算,计算结果自然是 ```123``` 。具体看下图 tuple4 和 tuple5 的输出值
|
||||
如果不加逗号,创建出来的就不是 tuple (元组),而是指 ```123``` 这个数了,这是因为括号 ()既可以表示 tuple,又可以表示数学公式中的小括号,这就产生了歧义,因此,Python 规定,这种情况下,按小括号进行计算,计算结果自然是 ```123``` 。具体看下图 tuple4 和 tuple5 的输出值
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
## 2、tuple(元组)的索引 ##
|
||||
@@ -50,7 +51,7 @@ print(tuple2[0])
|
||||
|
||||
输出的结果:
|
||||
|
||||

|
||||

|
||||
|
||||
## 4、修改 tuple (元组) ##
|
||||
|
||||
@@ -114,4 +115,4 @@ del tuple1
|
||||
|len(tuple)|计算元组元素个数|
|
||||
|max(tuple)|返回元组中元素最大值|
|
||||
|min(tuple)|返回元组中元素最小值|
|
||||
|tuple(seq)|将列表转换为元组|
|
||||
|tuple(seq)|将列表转换为元组|
|
||||
|
||||
Reference in New Issue
Block a user