Skip to content

Commit

Permalink
doc: update docs/python.md (#404)
Browse files Browse the repository at this point in the history
添加了使用remove方法移除list内容以及搜索list的方法
  • Loading branch information
hiyms committed Jul 29, 2023
1 parent a448246 commit 25f5aa4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ a_list[start:end:step]
>>> del li[0]
>>> li
['butter']
>>> li.remove('butter')
>>> li
[]
```

### 列表边界
Expand Down Expand Up @@ -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 判断
------------

Expand Down

0 comments on commit 25f5aa4

Please sign in to comment.