How to use the pass statement?

前端 未结 15 2398
旧时难觅i
旧时难觅i 2020-11-22 15:03

I am in the process of learning Python and I have reached the section about the pass statement. The guide I\'m using defines it as being a Null sta

15条回答
  •  失恋的感觉
    2020-11-22 15:34

    Honestly, I think the official Python docs describe it quite well and provide some examples:

    The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action. For example:

    >>> while True: ... pass # Busy-wait for keyboard interrupt (Ctrl+C) ...

    This is commonly used for creating minimal classes:

    >>> class MyEmptyClass: ... pass ...

    Another place pass can be used is as a place-holder for a function or conditional body when you are working on new code, allowing you to keep thinking at a more abstract level. The pass is silently ignored:

    >>> def initlog(*args): ... pass # Remember to implement this! ...

提交回复
热议问题