python基础入门----pass语句

本文介绍了Python编程中的pass语句,它作为一个占位符,用于未实现的函数或循环等。pass执行时不执行任何操作,是无操作的空语句。
摘要由CSDN通过智能技术生成

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语句?
  1. pass语法
  2. 例子: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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值