Python Forum

Full Version: a Word Inside Parenthesis in Class Decleration
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi There;
I am new to python. There is a class definition in python.

Output:
class SomeName(object) : """ You usually define data and code here (in the class body). """
What is object in this context?
Object refers to the base object class; it serves as the foundation of all objects in Python. In this particular case, this means that the class SomeName inherits from object - it has all the attributes and methods of object.

As I recall, this is the old syntax. Class definition used to require an explicit inheritance of object. In Python 3, you do not need to explicitly reference object.
You can write
class SomeName:
    """docstring"""
The class SomeName will be a subclass of 'object' which is the root ancestor of all classes.

In python 2, the explicit reference to 'object' was needed because for backwards compatibility, python 2's class system coexists with an old class system inherited from python 1. So in python 2 there are 'old style classes' (which don't inherit from 'object') and 'new style classes'. Only, the new style classes were new in 2001, but they're no longer new in 2019. In python 3, you can safely ignore the object parent class in the definition.