- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How does Python class inherit objects?
In Python 2.x there are two styles of classes depending on the presence or absence of a built-in type as a base-class −
‘Old style’ or "Classic" style classes: they have no built-in type as a base class −
>>> class OldFoo: # no base class ... pass >>> OldFoo.__bases__ ()
"New" style classes: they have a built-in type as a base class meaning that, directly or indirectly, they have object as a base class −
>>> class NewFoo(object): # directly inherit from object ... pass >>> NewFoo.__bases__ (<type 'object'>,)
In Python 3.x however, only new style classes allowed that have built-in type as a base-class −
There is no need to mention object in parentheses after the class name here in class declaration. Here classes inherit from object implicitly.
>>> class Foo: # directly inherit from object ... pass >>> Foo.__bases__ (<type 'object'>,)
- Related Articles
- How to inherit a class in C#?
- How to create class objects in Python?
- PHP Inherit the properties of non-class object?
- How does class inheritance work in Python?
- How does nested character class subtraction work in Python?
- Python program to define class for complex number objects
- How does class variables function in multi-inheritance Python classes?
- How to inherit multiple interfaces in Java?
- How to access Python objects within objects in Python?
- How do you compare Python objects with .NET objects?
- How we can convert Python objects into JSON objects?
- What does built-in class attribute __dict__ do in Python?
- What does built-in class attribute __doc__ do in Python?
- What does built-in class attribute __module__ do in Python?