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
python的pass语句