Skip to content

Commit cafb1ea

Browse files
🆕 新增查找目标值的Python示例代码
- 在`table.py`中新增了一个示例,展示如何在列表中查找目标值并输出其索引。 - 该示例使用了`enumerate`函数,增强了代码的实用性与可读性。
1 parent ef645ac commit cafb1ea

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

table.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
lists = [1,2,3,4,5,6,7,8,9,10]
2+
target = 9
3+
4+
for index , number in enumerate(lists):
5+
if number == target:
6+
print(f"找到目标值{target},索引为{index}")
7+
break
8+
else:
9+
print(f"未找到目标值{target}")

0 commit comments

Comments
 (0)