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?
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[...]
.
You can use the pass
command to achieve this
if True:
pass
else:
print "False"
You can use the pass
statement like this:
if True:
pass
else:
print "False"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With