Suppose we are writing code and a function or a class or the body of a loop is to be implemented later. If we want to run the code at this point, then the code will give syntax errors. So, we can use the pass statement in this case.
For example, we can write the definition of a function in the following way:
def multiplication(a, b): pass multiplication(2, 5)
The above code will give no syntax error. Later, we can implement the definition of the function in our own way.
Similarly, we can write a class in the following way so that we can implement the class later.
class A: pass
Similarly, we can write a for loop in the following way:
for i in range(6): pass
The pass statement here does nothing but avoids a syntax error.
Similarly, we can write:
while True: pass
The program will busy-wait until we hit Ctrl + C on the keyboard.






0 Comments