Python pass statement
In this article, you'll learn about pass statement. It is used as a placeholder for future implementation of functions, loops, etc.
Table of Contents
pass语句
在这篇文章,你将学习到pass语句。它作为一个占位符对将来的函数,循环等很重要。
表格内容
- 什么是pass语句?
- pass语法
- 例子:pass语句
What is pass statement in Python?
In Python programming, pass is a null statement. The difference between a comment andpass statement in Python is that, while the interpreter ignores a comment entirely, pass is not ignored.
However, nothing happens when pass is executed. It results into no operation (NOP).
什么是pass语句?
在python程序,pass是一个空语句。在python里pass语句和注释不同,解释器是完全忽略整个注释,pass不忽略。
然而,当pass执行,不会发生任何事。它的结果没有被操作(NOP).
Syntax of pass
pass
We generally use it as a placeholder.
Suppose we have a loop or a function that is not implemented yet, but we want to implement it in the future. They cannot have an empty body. The interpreter would complain. So, we use the pass statement to construct a body that does nothing.
pass语法
pass
我们一般用它作为一个占位符。
假设,我们有一个循环或一个函数已经不重要了,但是我们希望未来很重要。我们不能有一个空的主体。解释器会抱怨。因此,我们可以使用一个pass语句去建立一个主体,而不做任何事。
Example: pass Statement
# pass is just a placeholder for
# functionality to be added later.
sequence = {'p', 'a', 's', 's'}
for val in sequence:
pass
We can do the same thing in an empty function or class as well.
def function(args):
pass
class example:
pass
例子:pass语句
>>> sequence = {'p','a','s','s'}
>>> for val in sequence:
... pass
...
我们可以使用一个空的函数和类做同样的事。
def function(args):
pass
class example:
pass
本文介绍了Python编程中的pass语句,它作为一个占位符,用于未实现的函数或循环等。pass执行时不执行任何操作,是无操作的空语句。
680

被折叠的 条评论
为什么被折叠?



