Thanks but Ill pass

The pass keyword tells the Python interpreter to do nothing. It is usually used in class statements, but you'll also find it useful in while or for loops when the program requires no action. In this example, the argument_clinic() function does nothing if its argument is greater than or equal to 5:

>>> def argument clinic(minutes): ... if minutes >= 5: ... pass ... else:

>>> minutes = 4 >>> argument clinic(minutes) No it isn't! >>> minutes = 5

>>> argument clinic(minutes) # nothing happens >>>

Tip The pass statement is also useful when you are starting to build a program. You can create the skeleton of the program's code blocks by using pass and then fill in what the blocks do later. (But don't forget to take out pass!)

This example code will eventually solve all the world's problems, but for now it's just a placeholder:

def grand solution(problems):

solve all the world's problems here

# We will figure this out someday pass

Was this article helpful?

0 0

Post a comment