[Python] Empty functions/methods with just the docstring valid in Python?

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following valid Python code:

    class A:
    def __init__(self):
    """
    Some doc-string
    """
    def some_method(self):
    """
    Some other doc-string
    """

    def say():
    """
    Well that's it, no doc-string
    """

    a = A()
    print('works')


    And it outputs works.

    But I'm not able to understand how is this a perfectly valid Python code. Can somebody please help me to understand its functioning?

    Also, are there any PEPs which discourage/disallow such code?

    Continue reading...

Compartilhe esta Página