[Python] Does the @staticmethod decorator do anything?

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    I made these two classes:

    class A:
    @staticmethod
    def f(x):
    print("x is", x)

    class B:
    def f(x):
    print("x is", x)


    And used them like this:

    >>> A.f(1)
    x is 1
    >>> B.f(1)
    x is 1


    It looks like f became a static method on B even without the decorator. Why would I need the decorator?

    Continue reading...

Compartilhe esta Página