Avatar ·

Why is @staticmethod needed in Python

📁 Decorator, method, Advanced Python Topics, AI

There is a class printer. It has 2 methods that do the same thing. The difference is that one of the methods has the @staticmethod decorator, and the other does not. But I can call both methods without creating an instance of the class.

class printer():    ''' Test @staticmethod '''    def not_static_print(self, text = 'Example Text'):        print(text)    @staticmethod    def static_print(text = 'Example Text'):        print(text)

                    
                
Avatar ·

Strictly speaking, there are several interpreters of the Python language, written in different programming languages.

The reference implementation is the interpreter implementation in C - CPython.

There is also an interpreter implementation in Java (Jython), in .Net (IronPython), and even in Python itself (PyPy).

In most cases, the reference implementation is sufficient.

Do not confuse CPython and Cython - they are different things. The first is an interpreter, the second is an extension for the language. Since CPython is written in C, it can use structures specific to C. This is what the Cython project does - in Python code, you can declare a structure from the C language and then work with it. It is, by the way, extremely rarely needed, used in very specific projects.

Programs in Python are trans

Log in to leave an answer

Blogs