+ 2
What is the use of pass statement in python
it belongs to conditional statements
4 ответов
+ 7
Nothing happens when pass executes, so you can use it for things like a placeholder for a function that is defined but does not have any code yet or to ignore errors in a try-except codeblock by adding 'pass' to the except block (:
+ 6
pass tells python to skip that line and continue.
for example:
if True:
pass
else:
print("Hi")
#Output: Nothing
example 2:
if True:
print("Before pass")
pass
print("After pass")
else:
print("else")
#output:
Before pass
After pass
+ 1
OK I understood when pass executes nothing happens in the program.
+ 1
This example might help you.
class Character():
Type = "Alien "
Guns = 2
Height = 6.9
class ZombieType1(Character) : #Inheritance
pass
class ZombieType2(Character) :
pass
class ZombieType3(Character) :
pass
class ZombieType4(Character) :
pass
class ZombieBoss(Character) :
Guns = 9
Height = 9.6
Zombie1 = ZombieType1()
Zombie2 = ZombieType2()
Boss = ZombieBoss()