class Student(object):
    name = ""
    age = 0
    major = ""

    # The class "constructor" - It's actually an initializer 
    def __init__(self, name, age, major):
        self.name = name
        self.age = age
        self.major = major

def make_student(name, age, major):
    student = Student(name, age, major)
    return student

Note that even though one of the principles in Python's philosophy is "there should be one—and preferably only one—obvious way to do it", there are still multiple ways to do this. You can also use the two following snippets of code to take advantage of Python's dynamic capabilities:

class Student(object):
    name = ""
    age = 0
    major = ""

def make_student(name, age, major):
    student = Student()
    student.name = name
    student.age = age
    student.major = major
    # Note: I didn't need to create a variable in the class definition before doing this.
    student.gpa = float(4.0)
    return student

I prefer the former, but there are instances where the latter can be useful – one being when working with document databases like MongoDB.

Answer from Wulfram on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_classes.asp
Python Classes/Objects
Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a "blueprint" for creating objects.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-classes-and-objects
Python Classes and Objects - GeeksforGeeks
Let's create an object from Dog class. Python · class Dog: sound = "bark" dog1 = Dog() # Creating object from class print(dog1.sound) # Accessing the class · Output · bark · Explanation: sound attribute is a class attribute. It is shared across all instances of Dog class, so can be directly accessed through instance dog1.
Published   2 weeks ago
🌐
Python documentation
docs.python.org › 3 › tutorial › classes.html
9. Classes — Python 3.14.4 documentation
Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state. Compared with other programming languages, Python’s class mechanism adds classes with a minimum of new syntax and semantics.
🌐
BeginnersBook
beginnersbook.com › 2018 › 03 › python-class-and-objects
How to create Class and Objects in Python
March 14, 2019 - class MyNewClass: """This class demonstrates the creation of objects""" # instance attribute num = 100 # instance method def hello(self): print("Hello World!") # creating object of MyNewClass obj = MyNewClass() # prints attribute value print(obj.num) # calling method hello() obj.hello() # prints docstring print(MyNewClass.__doc__)
🌐
W3Schools
w3schools.com › python › python_oop.asp
Python OOP (Object-Oriented Programming)
Python is an object-oriented language, allowing you to structure your code using classes and objects for better organization and reusability. ... Tip: The DRY principle means you should avoid writing the same code more than once. Move repeated code into functions or classes and reuse it. Classes and objects are the two core concepts in object-oriented programming. A class defines what an object should look like, and an object is created based on that class.
Find elsewhere
🌐
Programiz
programiz.com › python-programming › object-oriented-programming
Python Object Oriented Programming (With Examples)
Then, we create instances of the Parrot class. Here, parrot1 and parrot2 are references (value) to our new objects. We then accessed and assigned different values to the instance attributes using the objects name and the . notation. To learn more about classes and objects, visit Python Classes and Objects
🌐
Wellsr
wellsr.com › python › basics › python-class-objects-and-class-applications
Creating and Using Python Class Objects and Iterators - wellsr.com
August 24, 2018 - This tutorial discusses Python class objects, class constructors, Python methods, underscore naming convention, attribute name mangling, and class object inheritance.
🌐
Real Python
realpython.com › python3-object-oriented-programming
Object-Oriented Programming (OOP) in Python – Real Python
December 15, 2024 - The four key concepts of OOP in Python are encapsulation, inheritance, abstraction, and polymorphism. You create an object in Python by instantiating a class, which involves calling the class name followed by parentheses.
🌐
Oreate AI
oreateai.com › blog › python-create-a-class-object
Python Create a Class Object - Oreate AI Blog
December 3, 2025 - These are characteristics that define our objects—in this case, houses might have colors and sizes. class House: def __init__(self, color, size): self.color = color # The 'self' keyword refers to the instance itself self.size = size # Each house will remember its own color and size · Creating Methods: Now let’s add some behavior!
🌐
Medium
medium.com › @ozorgwua › an-introduction-to-object-oriented-programming-in-python-a-beginner-friendly-explanation-10dfd3e0336b
An Introduction to Object-Oriented Programming in Python/ A Beginner Friendly Explanation | by Amarachukwu Ozorgwu | Feb, 2026 | Medium
February 27, 2026 - Object‑Oriented Programming is simply a way of organising your code into small, tidy units (classes and objects) that behave like real‑life things. If you enjoy my writing and would like to clap for me, that would be appreciated. You can find me on Linkedin . Follow my 30 days python series on Medium .
🌐
Reddit
reddit.com › r/learnpython › how do i automatically create objects that i can refer to and use later?
r/learnpython on Reddit: How do I automatically create objects that I can refer to and use later?
January 17, 2022 -

Basically I'm trying to make many objects without having to define each of them manually, and be able to use methods on specific ones later. I've tried this, from how I understood it on Stack Overflow

class clas:
    def __init__(self):
        self.name="obj{}".format(i)
        #someothercode
    def some_method(self):
        print(self.name)
        #someothercode

dict={}
for i in range(1,6):
    dict[i]=clas()

But when I try to use specific objects with something like "obj2.some_method()" later, it tells me they are not defined. I can only use that method in the for loop or in the init. I have also tried using __repr__, with the same result. I also tried using id, but it didn't help, although maybe I didn't really understand it. I already understand that neither repr nor name actually name objects, but I cannot find or maybe understand what I should be doing instead. I have tried to search for it several times, but all the answers seem to help only with attributes, not things you can refer to.

🌐
Towards Data Science
towardsdatascience.com › home › latest › coding the pong game from scratch in python
Coding the Pong Game from Scratch in Python | Towards Data Science
February 27, 2026 - Now continuing on our OOP approach to code this game, we will create the Ball class as the generic blueprint and create the ball object from it in our main Python file. We will create the ball as a turtle object, by making the Ball class inherit from the super class Turtle.
🌐
Sarthaks eConnect
sarthaks.com › 3473803 › how-do-you-create-an-object-in-python
How do you create an object in Python? - Sarthaks eConnect | Largest Online Education Community
LIVE Course for free · In Python, you can create an object by defining a class and then creating an instance of that class using the class constructor. Here's an example:
🌐
Programiz
programiz.com › python-programming › class
Python Classes and Objects (With Examples)
We use the class keyword to create a class in Python. For example, ... Here, we have created a class named ClassName. ... Note: The variables inside a class are called attributes. An object is called an instance of a class.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-object
Python object - GeeksforGeeks
July 12, 2025 - Based on these descriptions we make a village, here the village is the object in Python. When creating an object from a class, we use a special method called the constructor, defined as __init__(), to initialize the object's attributes.
🌐
Python documentation
docs.python.org › 3 › reference › datamodel.html
3. Data model — Python 3.14.4 documentation
It previously evaluated to True and emitted a DeprecationWarning since Python 3.9. This type has a single value. There is a single object with this value. This object is accessed through the literal ... or the built-in name Ellipsis. Its truth value is true. These are created by numeric literals and returned as results by arithmetic operators and arithmetic built-in functions.
🌐
Mimo
mimo.org › glossary › python › class
Mimo: The coding platform you need to learn Web Development, Python, and more.
A class in Python is a blueprint for creating objects. An object is an instance of a class, with its own unique attributes and methods. You define a class using the class keyword and initialize its attributes with the special __init__() method.
🌐
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
12
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)
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-classes-objects
Python Classes and Objects | DigitalOcean
August 4, 2022 - At first, you put the name of the new object which is followed by the assignment operator and the name of the class with parameters (as defined in the constructor). Remember, the number and type of parameters should be compatible with the parameters received in the constructor function.