python的pass语句_Python pass语句

python的pass语句

Python中的pass语句 (pass statement in Python)

In python pass statement is a null statement or we can say it's a dummy statement – which does nothing. It can be used where you do not want to execute any statement (i.e. you want to keep any block empty).

在python中, pass语句是一个空语句,或者我们可以说这是一个伪语句–什么都不做。 它可以用于您不想执行任何语句的地方(即,您想让任何块都为空)。

For example – if you have any blank body of any statement like if statement, loop statement, etc, we can use pass there.

例如–如果您在if语句,循环语句等任何语句的任何空白正文中,都可以在此处使用pass

Syntax of pass statement:

pass语句的语法:

    pass

Example 1: Here, we are writing two pass statement after the print statements

示例1:在这里,我们在print语句之后编写两个pass语句

# python example of pass statement

print("Hello")
pass
print("world!")
pass
print("Good bye!")

Output

输出量

Hello
world!
Good bye!

Example 2: Here, we are using pass statement to define an empty function

示例2:在这里,我们使用pass语句定义一个空函数

# python example of pass statement

def myfun():
    pass

def urfun():
    print("this is your function")
    
# main code
print("Hi")

# calling both of the functions
myfun()
urfun()

print("Bye!!!")

Output

输出量

Hi
this is your function
Bye!!!

Example 3: Here, we are taking an integer number, checking it's positive or negative – pass the execution if number is zero

示例3:在这里,我们取一个整数,检查它的正数或负数–如果数字为零,则通过执行

# python example of pass statement

num = 10

if num>0:
    print("It's a positive number")
elif num<0:
    print("It's a negative number")
else:
    pass

print("End of the program")

Output

输出量

It's a positive number
End of the program


翻译自: https://www.includehelp.com/python/pass-statement.aspx

python的pass语句

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值