Python Pass and Empty Class

What is the uses of pass statements ?

  • pass statement does nothing.
  • It can be used when a statement is required syntactically but the program requires no action.

Infinite loop with no action

Just busy wait infinite loop.
while True:                                                                     
    # print("welcome to python pass statement learning!");                       
$ python

Example python program for pass statement

for num in reversed([1, 2, 3, 4]):                                              
   if num == 3:                                                                 
      print("pass block");                                                      
       print("number :%d" % num);                                               
print "done!"  
$ python
number :4
pass block
number :2
number :1

Empty Class

Commonly used for creating minimal classes, bundling together a few named data items.
class EmptyClass:

How empty class can be used in python program ?

class Student:                                                                  
# Create an object for Empty Student Class                                      
student1 = Student();                                                           
# Fields of the object student1                                         = 'Student1';                                                     
student1.dept = 'computer science';                                             
student1.mark = 90;                                                             
print("name: %s" %;                                              
print("department: %s" % student1.dept);                                              
print("mark: %d" % student1.mark); 
$ python
name: Student1
department: computer science
mark: 90

Not implemented function

pass can be used in any function or conditional body when working on new code. it is allowing to think at a more abstract level.
# Remember to implement this!
def computeSalary(*args):
here pass statement is just ignored. here this computeSalary function needs to be implemented later.

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter