From 25f5aa4695311667784b89ee322120b7e8c591ff Mon Sep 17 00:00:00 2001 From: yms <84654050+hiyms@users.noreply.github.com> Date: Sun, 30 Jul 2023 02:42:34 +0800 Subject: [PATCH] doc: update docs/python.md (#404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加了使用remove方法移除list内容以及搜索list的方法 --- docs/python.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/python.md b/docs/python.md index 7887efc..40b3cb6 100644 --- a/docs/python.md +++ b/docs/python.md @@ -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 判断 ------------