Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 834 Bytes

pass-and-ellipsis.md

File metadata and controls

48 lines (34 loc) · 834 Bytes

Doing nothing with pass and Ellipsis

In python, you can do nothing by typing pass - people also use ... (Ellipsis), but this is also used in other places.

For ignoring exceptions:

try:
    f(x)
except ValueError:
    pass

For writing skeleton code (to me, pass looks like it's intended to be empty, ... looks like it will be filled in later).

def my_fcn():
    ...

You can put anything in place of the ... here though, so people often just write a docstring:

def my_fcn():
   """
   Do some things and stuff
   """

Via: Richard

Postscript

For skeleton code you could also do:

def my_fcn():
    raise NotImplementedError

or:

def my_fcn():
    return NotImplemented

(these do different things)