geekdoc-python-zh/docs/py4b/del-statement.md

21 lines
530 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 德尔声明
> 原文:<https://www.pythonforbeginners.com/basics/del-statement>
**del** 语句可以通过引用索引而不是值来从列表中删除一个项目。例如,如果您有一个包含五个值的列表,如下所示:
```py
a = [1, 2, 3, 4, 5]
```
并且您想要删除第二个列出的值(2),您可以使用 del 来执行此操作。第二个列出的值的索引为 1因此要删除该值del 语法需要如下所示:
```py
del a[1]
```
现在 a 看起来像这样:
```py
a = [1, 3, 4, 5]
```