What are other pass applications?

Asked

Viewed 161 times

4

In the documentation the statement pass is defined

pass is a null operation. When executed, nothing happens. Useful as a placeholder when syntactically a statement is required, but no code needs to be executed.

That is, it’s useful when I have something like this:

if aprovou_pagamento(p):
    pass
    # TODO(efetivar transação)
else:
    desefetivar_transacao(p.transacao)

because this would generate a syntax error:

if aprovou_pagamento(p):
    # TODO(efetivar transação)
else:
    desefetivar_transacao(p.transacao)

Otherwise, I can’t see any practical application, except under these conditions.

There are other applications for pass? In what other contexts it would be useful?

1 answer

4


It’s just that, of course you can use it in several places, not just one if.

An interesting case is when you want to create an abstract method, ie without implementation in that type, probably to be implemented in an inherited type, not to give error puts the pass in his body.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.