Prior to python 2.2 there were essentially two different types of class: Those defined by C extensions and C coded builtins (types) and those defined by python class statements (classes). This led to problems when you wanted to mix python-types and builtin types. The most common reason for this is subclassing. If you wanted to subclass the list type in python code, you were out of luck, and so various workarounds were used instead, such as subclassing the pure python implementation of lists (in the UserList module) instead.

This was a fairly ugly, so in 2.2 there was a move to unify python and builtin types, including the ability to inherit from them. The result is "new style classes". These do have some incompatible differences to old-style classes however, so for backward compatability the bare class syntax creates an old-style class, while the new behaviour is obtained by inheriting from object. The most visible behaviour differences are:

  • The method resolution order (MRO). There is a difference in behaviour in diamond-shaped inheritance hierarchies (where A inherits from both B and C, which both inherit from a common base class D. Previously, methods were looked up left-to right, depth first (ie A B D C D) However if C overloads a member of D, it won't be used by A (as it finds D's implementation first) This is bad for various styles of programming (eg. using mixin classes). New style classes will treat this situation as A B C D, (look at the __mro__ attribute of a class to see the order it will search)

  • The __new__ constructor is added, which allows the class to act as a factory method, rather than return a new instance of the class. Useful for returning particular subclasses, or reusing immutable objects rather than creating new ones without having to change the creation interface.

  • Descriptors. These are the feature behind such things as properties, classmethods, staticmethods etc. Essentially, they provide a way to control what happens when you access or set a particular attribute on a (new style) class.

Answer from Brian on Stack Overflow
๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ Classes_and_Objects
Classes and Objects - Learn Python - Free Interactive Python Tutorial
You can save 25% off your Datacamp ... an encapsulation of variables and functions into a single entity. Objects get their variables and functions from classes......
Top answer
1 of 4
52

Prior to python 2.2 there were essentially two different types of class: Those defined by C extensions and C coded builtins (types) and those defined by python class statements (classes). This led to problems when you wanted to mix python-types and builtin types. The most common reason for this is subclassing. If you wanted to subclass the list type in python code, you were out of luck, and so various workarounds were used instead, such as subclassing the pure python implementation of lists (in the UserList module) instead.

This was a fairly ugly, so in 2.2 there was a move to unify python and builtin types, including the ability to inherit from them. The result is "new style classes". These do have some incompatible differences to old-style classes however, so for backward compatability the bare class syntax creates an old-style class, while the new behaviour is obtained by inheriting from object. The most visible behaviour differences are:

  • The method resolution order (MRO). There is a difference in behaviour in diamond-shaped inheritance hierarchies (where A inherits from both B and C, which both inherit from a common base class D. Previously, methods were looked up left-to right, depth first (ie A B D C D) However if C overloads a member of D, it won't be used by A (as it finds D's implementation first) This is bad for various styles of programming (eg. using mixin classes). New style classes will treat this situation as A B C D, (look at the __mro__ attribute of a class to see the order it will search)

  • The __new__ constructor is added, which allows the class to act as a factory method, rather than return a new instance of the class. Useful for returning particular subclasses, or reusing immutable objects rather than creating new ones without having to change the creation interface.

  • Descriptors. These are the feature behind such things as properties, classmethods, staticmethods etc. Essentially, they provide a way to control what happens when you access or set a particular attribute on a (new style) class.

2 of 4
13

class foo(object): is the 'new' way of declaring classes.

This change was made in python 2.2, see this PEP for an explanation of the differences.

Discussions

class - What is the difference between objects and classes in Python? - Stack Overflow
I encountered a text saying: ... classes and objects .... I was wondering what is the difference between objects and classes in python? I thought all classes are objects, but in that case, author More on stackoverflow.com
๐ŸŒ stackoverflow.com
Im new to python. Classes and objects
Yes. You have the basic idea. Here's my guide to flesh that out a bit more ... Classes for Beginners v2.1 May 2023 A lot of beginners struggle to get their heads around classes, but they are pretty much fundamental to object orientated programming (OOPs). They can be thought of as the programming equal of moulds used in factories as templates (or blueprints) for making lots of things that are identical. Imagine pouring molten iron into a mould to make a simple iron pot. You might produce a set of instructions to be included with the pots that tell an owner how to cook using the pot, how to care for it, etc. The same instructions apply to every pot, but what owners actually do is entirely up to them. Some might make soup, another person a stew, etc. Python classes A class defines the basics of a possible Python object and some methods that come with it Methods are like functions, but apply to objects, known as instances, made using a class When we create a Python object using a class, we call it "creating an instance of a class" - an instance is just another Python object If you have a class called Room, you would create instances like this: lounge = Room() kitchen = Room() hall = Room() As you would typically want to store the main dimensions (height, length, width) of a room, whatever it is used for, it makes sense to define that when the instance is created. You would therefore have a method called __init__ that accepts height, length, width and when you create an instance of Room you would provide that information: lounge = Room(1300, 4000, 2000) The __init__ method is called automatically when you create an instance. It is short for initialise (intialize). It is possible to specify default values in an __init__ method, but this doesn't make a lot of sense for the size of a room. Accessing attributes of a class instance You can reference the information using lounge.height, lounge.width, and so on. These are attributes of the lounge instance. We are assuming the measurements are in mm. A method can be included in the class that converts between mm and ft. Thus, for example, we can then write lounge.height_in_ft(). printing an attribute You can output the value of any attribute by just using the name of the instance followed by a dot and the attribute name. For example, print(lounge.height) property decorator A useful decorator is @property, which allows you to refer to a method as if it is an attribute. This would allow you to say lounge.height_in_ft instead of lounge.height_in_ft(). In the example code shown later, @property is used for width_in_ft but not height_in_ft. The use of self to refer to an instance Methods in classes are usually defined with a first parameter of self: def __init__(self, height, length, width): # code for __init__ def height_in_ft(self): # code to return height The self is a shorthand way of referring to an instance. The automatic passing of the reference to the instance (assigned to self) is a key difference between a function call and a method call. When you use lounge.height_in_ft() the method knows that any reference to self means the lounge instance, so self.height means lounge.height but you don't have to write the code for each individual instance. Thus, kitchen.height_in_ft() and bathroom.height_in_ft() use the same method, but you don't have to pass the height of the instance as the method can reference it using self.height human-readable representation of an instance If you want to output all the information about an instance, that would get laborious. There's a method you can add called __str__ which returns a string representation of an instance. This is used automatically by functions like str and print. The example code below includes both the laborious way and using the above method. magic methods The standard methods you can add that start and end with a double underscore, like __init__, __str__, and many more, are often called magic methods or dunder methods where dunder is short for double underscore. EXAMPLE Room class The code shown at the end of this post/comment will generate the following output: Lounge height: 1300 length: 4000 width: 2000 Snug: height: 1300, length: 2500 width: 2000 Lounge length in feet: 4.27 Snug wall area: 11700000.00 in sq.mm., 125.94 in sq.ft. Snug width in feet: 6.56 Note that a method definition that is preceded by the command, @staticmethod (a decorator) is really just a function that does not include the self reference to the calling instance. It is included in a class definition for convenience and can be called by reference to the class or the instance: Room.mm_to_ft(mm) lounge.mm_to_ft(mm) Here's the code for the full programme: class Room(): def __init__(self, name, height, length, width): self.name = name self.height = height self.length = length self.width = width @staticmethod def mm_to_ft(mm): return mm * 0.0032808399 @staticmethod def sqmm_to_sqft(sqmm): return sqmm * 1.07639e-5 def height_in_ft(self): return Room.mm_to_ft(self.height) @property def width_in_ft(self): return Room.mm_to_ft(self.width) def length_in_ft(self): return Room.mm_to_ft(self.length) def wall_area(self): return self.length * 2 * self.height + self.width * 2 * self.height def __str__(self): return (f"{self.name}: " f"height: {self.height}, " f"length: {self.length} " f"width: {self.width}" ) lounge = Room('Lounge', 1300, 4000, 2000) snug = Room('Snug', 1300, 2500, 2000) print(lounge.name, "height:", lounge.height, "length:", lounge.length, "width:", lounge.width) print(snug) # uses __str__ method # f-strings are used for formatting, the :.2f part formats decimal numbers rounded to 2 places print(f"{lounge.name} length in feet: {lounge.height_in_ft():.2f}") # note, () to call method print(f"{snug.name} wall area: {snug.wall_area():.2f} in sq.mm., " f"{snug.sqmm_to_sqft(snug.wall_area()):.2f} in sq.ft." ) print(f"Snug width in feet: {snug.width_in_ft:.2f}") # note, no () after method More on reddit.com
๐ŸŒ r/learnpython
14
15
July 12, 2023
Using class like an object in Python - Software Engineering Stack Exchange
I am learning from Learn Python the hard way where I have come across a study drill where they want to know that whether a class can be used like an object. As I have experimented: class A(object... More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
June 24, 2014
is there a difference between class(): and class(object): in python 2.6-3.x? - Stack Overflow
Before py2.6 it's been answered here. Difference between class foo and class foo(object) in Python But for python2.6+ and python3.x, is the first one wrong? class Foo(): pass vs class Foo(object)... More on stackoverflow.com
๐ŸŒ stackoverflow.com
People also ask

Q1. What is a class in Python?
A class is a template for creating objects. It defines the attributes (variables) and behaviours (methods) that objects created from the class will have.
๐ŸŒ
intellipaat.com
intellipaat.com โ€บ home โ€บ blog โ€บ python classes and objects
Python Classes and Objects (With Examples)
Q5. Why should we use classes and objects in Python?
Classes and objects help to structure code, increase reuse, and follow the principles of OOP like encapsulation and inheritance to structure the code.
๐ŸŒ
intellipaat.com
intellipaat.com โ€บ home โ€บ blog โ€บ python classes and objects
Python Classes and Objects (With Examples)
Q2. How do you create an object in Python?
You can create an object by calling the name of the class like a function, for example: obj = ClassName() creates an instance of ClassName.
๐ŸŒ
intellipaat.com
intellipaat.com โ€บ home โ€บ blog โ€บ python classes and objects
Python Classes and Objects (With Examples)
๐ŸŒ
Quora
quora.com โ€บ What-is-the-difference-between-classes-and-objects-in-Python
What is the difference between classes and objects in Python? - Quora
Answer (1 of 7): A class is the prototype of an object. An object is an instance of a class. This is a class: [code py] class Car: def __init__(self, brand, model): self.brand = brand self.model = model [/code] This is an object: [code py] bmw = Car("BMW", "535i") [/code]
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-classes-and-objects
Python Classes and Objects
Problem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More ยท Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-classes-and-objects
Python Classes and Objects - GeeksforGeeks
dog1.name accesses the objectโ€™s instance attribute and dog1.species accesses the shared class attribute. __str__() method allows us to define a custom string representation of an object. By default, when we print an object or convert it to a string using str(), Python uses the default implementation, which returns a string like <__main__.ClassName object at 0x00000123>.
Published: 2 weeks ago
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ python object-oriented programming (oop) โ€บ classes and objects in python
Python Classes and Objects [Guide] โ€“ PYnative
February 24, 2024 - As you can see, Jessa is female, and she works as a Software engineer. On the other hand, Jon is a male, and he is a lawyer. Here, both objects are created from the same class, but they have different states and behaviors. In Python, class is defined by using the class keyword.
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ im new to python. classes and objects
r/learnpython on Reddit: Im new to python. Classes and objects
July 12, 2023 -

From what I understand....

Class - is basically the blueprint from which you create objects. This is where you state what attributes the item will have (e.g. name, colour) but you wont actually assign the value of the attribute (e.g. iphone, red).

Object - is basically the values (e.g. the actual name/colour of the item) to the attributes/properties you chose the item to have

Is that right? If possible, if you have anything to add. I would really appreciate if you explain to me in an easy to understand way. Im new to python and computers as a whole but slowly learning

Thankyou in advance

Top answer
1 of 5
13
Yes. You have the basic idea. Here's my guide to flesh that out a bit more ... Classes for Beginners v2.1 May 2023 A lot of beginners struggle to get their heads around classes, but they are pretty much fundamental to object orientated programming (OOPs). They can be thought of as the programming equal of moulds used in factories as templates (or blueprints) for making lots of things that are identical. Imagine pouring molten iron into a mould to make a simple iron pot. You might produce a set of instructions to be included with the pots that tell an owner how to cook using the pot, how to care for it, etc. The same instructions apply to every pot, but what owners actually do is entirely up to them. Some might make soup, another person a stew, etc. Python classes A class defines the basics of a possible Python object and some methods that come with it Methods are like functions, but apply to objects, known as instances, made using a class When we create a Python object using a class, we call it "creating an instance of a class" - an instance is just another Python object If you have a class called Room, you would create instances like this: lounge = Room() kitchen = Room() hall = Room() As you would typically want to store the main dimensions (height, length, width) of a room, whatever it is used for, it makes sense to define that when the instance is created. You would therefore have a method called __init__ that accepts height, length, width and when you create an instance of Room you would provide that information: lounge = Room(1300, 4000, 2000) The __init__ method is called automatically when you create an instance. It is short for initialise (intialize). It is possible to specify default values in an __init__ method, but this doesn't make a lot of sense for the size of a room. Accessing attributes of a class instance You can reference the information using lounge.height, lounge.width, and so on. These are attributes of the lounge instance. We are assuming the measurements are in mm. A method can be included in the class that converts between mm and ft. Thus, for example, we can then write lounge.height_in_ft(). printing an attribute You can output the value of any attribute by just using the name of the instance followed by a dot and the attribute name. For example, print(lounge.height) property decorator A useful decorator is @property, which allows you to refer to a method as if it is an attribute. This would allow you to say lounge.height_in_ft instead of lounge.height_in_ft(). In the example code shown later, @property is used for width_in_ft but not height_in_ft. The use of self to refer to an instance Methods in classes are usually defined with a first parameter of self: def __init__(self, height, length, width): # code for __init__ def height_in_ft(self): # code to return height The self is a shorthand way of referring to an instance. The automatic passing of the reference to the instance (assigned to self) is a key difference between a function call and a method call. When you use lounge.height_in_ft() the method knows that any reference to self means the lounge instance, so self.height means lounge.height but you don't have to write the code for each individual instance. Thus, kitchen.height_in_ft() and bathroom.height_in_ft() use the same method, but you don't have to pass the height of the instance as the method can reference it using self.height human-readable representation of an instance If you want to output all the information about an instance, that would get laborious. There's a method you can add called __str__ which returns a string representation of an instance. This is used automatically by functions like str and print. The example code below includes both the laborious way and using the above method. magic methods The standard methods you can add that start and end with a double underscore, like __init__, __str__, and many more, are often called magic methods or dunder methods where dunder is short for double underscore. EXAMPLE Room class The code shown at the end of this post/comment will generate the following output: Lounge height: 1300 length: 4000 width: 2000 Snug: height: 1300, length: 2500 width: 2000 Lounge length in feet: 4.27 Snug wall area: 11700000.00 in sq.mm., 125.94 in sq.ft. Snug width in feet: 6.56 Note that a method definition that is preceded by the command, @staticmethod (a decorator) is really just a function that does not include the self reference to the calling instance. It is included in a class definition for convenience and can be called by reference to the class or the instance: Room.mm_to_ft(mm) lounge.mm_to_ft(mm) Here's the code for the full programme: class Room(): def __init__(self, name, height, length, width): self.name = name self.height = height self.length = length self.width = width @staticmethod def mm_to_ft(mm): return mm * 0.0032808399 @staticmethod def sqmm_to_sqft(sqmm): return sqmm * 1.07639e-5 def height_in_ft(self): return Room.mm_to_ft(self.height) @property def width_in_ft(self): return Room.mm_to_ft(self.width) def length_in_ft(self): return Room.mm_to_ft(self.length) def wall_area(self): return self.length * 2 * self.height + self.width * 2 * self.height def __str__(self): return (f"{self.name}: " f"height: {self.height}, " f"length: {self.length} " f"width: {self.width}" ) lounge = Room('Lounge', 1300, 4000, 2000) snug = Room('Snug', 1300, 2500, 2000) print(lounge.name, "height:", lounge.height, "length:", lounge.length, "width:", lounge.width) print(snug) # uses __str__ method # f-strings are used for formatting, the :.2f part formats decimal numbers rounded to 2 places print(f"{lounge.name} length in feet: {lounge.height_in_ft():.2f}") # note, () to call method print(f"{snug.name} wall area: {snug.wall_area():.2f} in sq.mm., " f"{snug.sqmm_to_sqft(snug.wall_area()):.2f} in sq.ft." ) print(f"Snug width in feet: {snug.width_in_ft:.2f}") # note, no () after method
2 of 5
7
The blueprint analogy is not bad but it's just an analogy, it does not hold to reality. The better description is that a class is a type. And like all types in python it has attributes and methods. You know that floating point numbers in python are usually refer as a type. That type is float. It is actually a class and every time you create a float variable you are creating an object of the class float. x = 3.1415 is the same as x = float(3.1415) Which looks more like an object created from a class and a value. And yes there are all kinds of attributes and methods defined in the float class. For example the float class has a method as_integer_ratio() which will return a numerator and a denominator representing the value of the float as a fraction. print(x.as_integer_ratio()) output (7074029114692207, 2251799813685248)
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ class
Python Classes and Objects (With Examples)
Since many houses can be made from the same description, we can create many objects from a class. We use the class keyword to create a class in Python.
๐ŸŒ
W3Resource
w3resource.com โ€บ python-interview โ€บ explain-the-difference-between-a-class-and-object-in-python.php
Explain the difference between a class and an object in Python
In summary, a class is a template or blueprint that defines the structure and behavior of objects. An object is an instance of that class, representing a specific entity with its own set of attributes and methods.
๐ŸŒ
Real Python
realpython.com โ€บ python-classes
Python Classes: The Power of Object-Oriented Programming โ€“ Real Python
August 2, 2026 - Instance attributes hold data unique to each object, while class attributes are shared across all instances. Python classes support single and multiple inheritance, enabling code reuse through class hierarchies.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ class vs. object: what are the differences?
Class Vs Object - What are the Differences? - Scaler Topics
April 3, 2024 - Objects, on the other hand, are instances created from these blueprints, each having unique values but sharing common behaviors. ... A class is a blueprint or template for creating objects. It defines the data members and methods that objects will have.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-difference-between-a-class-and-an-object-in-Python
What is the difference between a class and an object in Python? - Quora
Answer (1 of 2): You can take it like this. Let's assume class as a set and object as a subset of it. For example : Cars is a class which is a category Okay!! and Tata, Honda, BMW are objects . Difference is an object can be part of class but class is a set it can be a part of an object.
๐ŸŒ
Internshala
trainings.internshala.com โ€บ home โ€บ programming โ€บ classes and objects in python
Classes and Objects in Python - Key Differences, Syntax, Examples, & More
July 6, 2023 - Classes are used to create objects, which can be used to store and manipulate data. Creating a class in Python is done using the keyword โ€˜classโ€™ followed by the name of the desired class.
๐ŸŒ
Medium
medium.com โ€บ @reetesh043 โ€บ the-ultimate-guide-to-python-classes-and-objects-8ecac5a1a055
The Ultimate Guide to Python Classes and Objects | by Reetesh Kumar | Medium
June 16, 2025 - Python is an object-oriented programming language, which means it allows you to organize code using classes and objects. In simple terms, a class is like a blueprint, and an object is an instance of that blueprint โ€” each object has the structure ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 46636267 โ€บ python-class-as-object
Python class as object - Stack Overflow
I wonder if the class below becomes an object in a moment when is defined or does it become and object in the moment when I instantiate it? class BlaBlaCar(object): def __init__(self): ...
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ python classes and objects
Python Classes and Objects (With Examples)
October 14, 2025 - ... Code Copied! ... โ€‹In Python, an object is a specific instance of a class that holds data (attributes) and performs the same actions (methods) that are specified by the class.