doc: update docs/python.md (#404)

添加了使用remove方法移除list内容以及搜索list的方法
This commit is contained in:
yms 2023-07-30 02:42:34 +08:00 committed by GitHub
parent a448246060
commit 25f5aa4695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -692,6 +692,9 @@ a_list[start:end:step]
>>> del li[0]
>>> li
['butter']
>>> li.remove('butter')
>>> li
[]
```
### 列表边界
@ -750,6 +753,19 @@ IndexError: list index out of range
['re', 're', 're']
```
### 搜索
```python
>>> nums = [40, 36, 89, 2, 36, 100, 7, -20.5, -999]
>>> nums.index(2)
3
>>> nums.index(100, 3, 7) # 搜索3-7之间的元素
5
>>> nums.index(7, 4) # 搜索4之后的元素
6
```
当寻找一个不存在的值时,抛出`ValueError`
Python 判断
------------