Looking at some of the code other people have written for the project I am currently working on, I often see if statements in the following form.
if condition:
do this
else:
pass
Is there a reason pass
is used here? Could the entire else
statement not just be left out? Why would you include the section with pass
? Similarly I also see this:
if condition:
pass
else:
do this
Why would you write the code this way, when you could do it this way:
if not condition:
do this
Is there a reason for using the pass
command that I am missing, or are these uses of pass
superfluous?
pass
is usually a "to do" placeholder. In Python you cannot declare functions without implementation or any code block without a body for that matter, for example if condition: (do nothing)
, so you just put pass
there to make it valid. pass
does nothing.
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