What is use of @classmethod, @staticmethod, @property in Python?

devquora
devquora

Posted On: Feb 22, 2018

 

Uses of @classmethod, @staticmethod, @property in Python.

The classmethod() in the python is used to return the class name for the function that is passed.

Syntax

classmethod(function) 

Here, the parameter is the function name and it returns the class method for the function.

The staticmethod() in the pythons returns the static function for the function that is passed.

Syntax

staticmethod(function) 

Here, the parameter is the function name. It returns the static method for the given function.

The property() function returns the property attribute given the parameters.

Syntax

property(fget, fset, fdel, doc) 

Here, fget() is used to get the value of attribute, fset() is used to set the value of attribute, fdel() is used to delete the attribute value, and doc() contains the documentation for the attribute.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Python Interview Questions

     How is Python different from Java?

    Java and Python differ in typing, syntax, and speed, but both are valuable for developers. Java uses static typing and braces for blocks, while Python uses dynamic typing and indentation. Python is ge..

    Python Interview Questions

    How does exception handling in Python differ from Java?

    Python’s try-except block allows for effective exception handling, enabling programmers to catch and handle errors without ending the program. This technique ensures that errors can be managed grace..

    Python Interview Questions

    What is a module and package in Python?

    Python modules are ".py" files with classes, functions, and variables. Packages are directories containing modules and sub-packages, marked by an init.py file. This file can be empty but indicates the..