Examples of pass statement in Python Programming

0

the pass statement is a null statement. The difference between a comment and a pass statement is that while the interpreter ignores a comment entirely.

Example :

Pass

All Contributions

pass statement get executed when the condition is true :

li =['a', 'b', 'c', 'd']
for i in li:
    if(i =='a'):
        pass
    else:
        print(i)

pass statement can be used with conditional statements :

a = 10
b = 20
if(a<b):
  pass
else:
  print("b<a")

pass statement can be used in for loop when user doesn’t know what to code inside the loop :

n = 10
for i in range(n):  
  # pass can be used as placeholder
  # when code is to added later
  pass

Pass statement :

'''pass is just a placeholder for
functionality to be added later.'''
sequence = {'p', 'a', 's', 's'}
for val in sequence:
    pass

Pass statement :

'''pass is just a placeholder for
functionality to be added later.'''
sequence = {'p', 'a', 's', 's'}
for val in sequence:
    pass

total contributions (6)

New to examplegeek.com?

Join us