7

I recall there was a dummy statement that was the equivalent of do nothing or fill in the blank space after the if, elif, else, and for statements to keep the expected indentation.

The below example will not work

if True:
    #I want to simply pass this branch
    # ... NOP command here
else:
    print "False"

How can I achieve this?

Mark Skelton
  • 3,663
  • 4
  • 27
  • 47
Radu Ionescu
  • 3,462
  • 5
  • 24
  • 43

3 Answers3

13

There's pass:

def foo():
    pass

In Python 3 there's also the ellipsis ...*, which wasn't really meant for this, but is also sometimes used:

def foo():
    ...

Semantically, I would expect to see ... when that part isn't written yet, as a stub, and pass when there's never going to be code there.


* The ellipsis also exists in Python 2, but can't be used outside the square brackets in something like foobar[...].

L3viathan
  • 26,748
  • 2
  • 58
  • 81
4

You can use the pass command to achieve this

if True:
    pass
else:
    print "False"
PKuhn
  • 1,338
  • 1
  • 14
  • 30
2

You can use the pass statement like this:

if True:
    pass
else:
    print "False"
Mark Skelton
  • 3,663
  • 4
  • 27
  • 47