6.13. The Pass Statement

The pass statement provides a way of saying “do nothing” that can be very useful during program development. For example, you want to lay out an if statement in which you have not yet filled in one of the branches but you want to be able to execute the program:

CD-ROM reference=6046.txt
if x > y:
      x = x - 1
elif x == y:
      # XXX deal with this case later.
      pass
else:
      print "Hello World"

The pass statement is also used with methods as a way of indicating that the method should be overridden by a subclass to do something useful. This idea is used heavily in the SAX API, which we discuss in chapter 10.

 CD-ROM reference=6047.txt class DocumentHandler: def characters(str): # Override this method to do something useful. pass ...

Get XML Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.