You probably want something like a Coin class for penny, nickel, dime, quarter to inherit from. Also you should only have one init method

class Coin():
    def __init__(self,weight,height):
        self.weight = weight
        self.height = height

class Penny(Coin):
    def __init__(self):
        Coin.__init__(self,2.5,1.52)
Answer from Jack burridge on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_classes.asp
Python Classes
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. ... Note: Each object is independent and has its own copy of the class properties. class definitions cannot be empty, but if you for some reason have a class definition with no content, put in the pass statement to ...
🌐
Python documentation
docs.python.org › 3 › tutorial › classes.html
9. Classes — Python 3.14.3 documentation
Valid attribute names are all the names that were in the class’s namespace when the class object was created. So, if the class definition looked like this: class MyClass: """A simple example class""" i = 12345 def f(self): return 'hello world' then MyClass.i and MyClass.f are valid attribute references, returning an integer and a function object, respectively. Class attributes can also be assigned to, so you can change the value of MyClass.i by assignment.
Discussions

How to create a Python class - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I'm working on a project and didn't do a good example of what I needed help with earlier so my thread was closed. What I need help doing is creating a class in Python that defines penny as an ... More on stackoverflow.com
🌐 stackoverflow.com
Python Class tutorial
Hi there i have completed a an exercise from a book and wanted you guys to have a look, I think its giving me back the results needed but i cant tell for sure if i have answered the questions rightly and the code i wrote is not error prone. better coding suggestions are welcome: “”" User ... More on discuss.python.org
🌐 discuss.python.org
3
0
April 29, 2023
Understanding classes, init and self
Could you explain this code excerpt? I am learning and trying to get in touch with the logic of classes · The __init__ method initialises a new instance (object) of the class NewWindow. The actual creation of the instance is done by a separate method __new__, before __init__ is called. More on discuss.python.org
🌐 discuss.python.org
19
0
February 16, 2024
How do you create a Python class file?
You can create a class file as simply as you create any python script file with extension .py. Simply create a new file and define all the classes inside that file. thats it, you have created a class file. myClass.py to refer to those classes contained in myClass file, simply import it. More on urbanpro.com
🌐 urbanpro.com
2
0
July 10, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-classes-and-objects
Python Classes and Objects - GeeksforGeeks
It is shared across all instances of Dog class, so can be directly accessed through instance dog1. __init__() method acts as a constructor and is automatically executed when an object is created. It is used to initialize the attributes of the object with the values provided at the time of object creation.
Published   1 week ago
🌐
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.
🌐
Quora
quora.com › How-do-you-create-a-private-class-in-Python
How to create a private class in Python - Quora
Answer: In python there is no formal private keyword, instead it is achieved through the naming convention. Typically, local variable has a naming convention of a single underscore carries and has a local variable convention meaning. Double pre underscore is used for name mangling of the subclass...
🌐
Reddit
reddit.com › r › learnpython › comments › 1162yka › creating_classes
Creating classes : r/learnpython
It has been 2 weeks since I started ... chores and errands). I'm seriously having more fun learning to code a game in Python and write NPC dialogue branching pathways in a JSON than I ever did with any other creative endeavor....
Find elsewhere
🌐
Real Python
realpython.com › python-classes
Python Classes: The Power of Object-Oriented Programming – Real Python
5 days ago - To create an object of a Python class like Circle, you must call the Circle() class constructor with a pair of parentheses and a set of appropriate arguments. What arguments? In Python, the class constructor accepts the same arguments as the .__init__() method.
🌐
Python documentation
docs.python.org › 3 › reference › datamodel.html
3. Data model — Python 3.14.3 documentation
These objects normally act as factories for new instances of themselves, but variations are possible for class types that override __new__(). The arguments of the call are passed to __new__() and, in the typical case, to __init__() to initialize the new instance. Instances of arbitrary classes can be made callable by defining a __call__() method in their class. Modules are a basic organizational unit of Python code, and are created by the import system as invoked either by the import statement, or by calling functions such as importlib.import_module() and built-in __import__().
🌐
Python.org
discuss.python.org › python help
Python Class tutorial - Python Help - Discussions on Python.org
April 29, 2023 - Hi there i have completed a an exercise from a book and wanted you guys to have a look, I think its giving me back the results needed but i cant tell for sure if i have answered the questions rightly and the code i wrote is not error prone. better coding suggestions are welcome: “”" User Class: Test 1: 1 Make a class called User.
🌐
pytest
docs.pytest.org › en › stable › getting-started.html
Get Started - pytest documentation
Once you develop multiple tests, you may want to group them into a class. pytest makes it easy to create a class containing more than one test: # content of test_class.py class TestClass: def test_one(self): x = "this" assert "h" in x def test_two(self): x = "hello" assert hasattr(x, "check") pytest discovers all tests following its Conventions for Python test discovery, so it finds both test_ prefixed functions.
🌐
GeeksforGeeks
geeksforgeeks.org › python › creating-instance-objects-in-python
Creating Instance Objects in Python - GeeksforGeeks
July 23, 2025 - Example 2: In this example, we create a base class Animal and a derived class Dog. We use super() to call the parent class constructor and set the species to "Dog" by default.
🌐
UrbanPro
urbanpro.com › python › learn python
How do you create a Python class file? - UrbanPro
July 10, 2022 - Simply create a new file and define all the classes inside that file. thats it, you have created a class file. myClass.py to refer to those classes contained in myClass file, simply import it.
🌐
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)
🌐
OneUptime
oneuptime.com › home › blog › how to create classes and objects in python
How to Create Classes and Objects in Python
January 25, 2026 - It runs automatically when you create an instance: class Dog: """A Dog with a name and age.""" def __init__(self, name, age): # self refers to the instance being created self.name = name self.age = age # Create instances buddy = Dog("Buddy", 3) max_dog = Dog("Max", 5) print(buddy.name) # Buddy print(max_dog.age) # 5
🌐
Pydantic
docs.pydantic.dev › latest › concepts › models
Models - Pydantic Validation
Both the new type parameter syntax (introduced by PEP 695 in Python 3.12) and the old syntax are supported (refer to the Python documentation for more details). Here is an example using a generic Pydantic model to create an easily-reused HTTP response payload wrapper: Python 3.9 and abovePython 3.12 and above (new syntax) from typing import Generic, TypeVar from pydantic import BaseModel, ValidationError DataT = TypeVar('DataT') # (1)! class DataModel(BaseModel): number: int class Response(BaseModel, Generic[DataT]): # (2)!
🌐
Reddit
reddit.com › r/learnpython › when is creating classes a good approach compared to just defining functions?
r/learnpython on Reddit: When is creating classes a good approach compared to just defining functions?
January 29, 2024 -

This might seem like an ignorant post, but I have never really grasped the true purpose of classes in a very practical sense, like I have studied the OOP concepts, and on paper like I could understand why it would be done like that, but I can never seem to incorporate them. Is their use more clear on bigger projects or projects that many people other than you will use?

For context, most of my programming recently has been numerical based, or some basic simulations, in almost all of those short projects I have tried, I didn't really see much point of using classes. I just find it way easier in defining a a lot of functions that do their specified task.

Also if I want to learn how to use these OOP concepts more practically, what projects would one recommend?

If possible, can one recommend some short projects to get started with (they can be of any domain, I just want to learn some new stuff on the side.)

Thanks!

Top answer
1 of 17
66
Classes are useful when there is state and operations on that state and keeping them tightly bound together is a useful abstraction. That is the central insight of OOP: sometimes state and operations belong together as a single unit. In the end, all software gets translated into a stream of CPU opcodes that get executed and anything else is about making the software comprehensible to humans. So you should write software in whatever way makes it most comprehensible to the people reading it. If most of your programming has been numerical and scientific computing then it's not very surprising that you haven't found classes very useful. That problem domain is usually about long sequences of numerical data and transforming that data into new long sequences of numerical data; you're using classes under the covers here (lists and dictionaries are classes) but you're not going to write many. Numerical computing doesn't often have long-lived state that needs managing, it usually has a question posed and an answer produced. People who come from an OOP background and attempt numerical computing often produce quite a mess when they try to apply the class abstraction to it and it doesn't really fit. People who come from a scientific background and try to use the software scripting they've done before the build a user application also usually produce a mess as the sort of abstractions they are used to don't really scale to software that has to handle all possible inputs and run reliably every time for a long time and where crashes are never-events, not something that can be investigated and tried again.
2 of 17
20
It's a good approach when there is a tight coupling between your data and the functions operating on the data. eg. "hello".upper(), where upper is implemented as a method on the string class, because it acts on the string. When there is no such coupling, freestanding functions make way more sense than writing a class. There is a school of thought coming mostly from Java that everything should be in a class. This is Bullshit, and has led to the overengineered and hard to maintain mess that people lovingly call "Enterprise Java", where code is polluted with myriads of superfluous "Doer-classes", the only purpose of which is to be wrappeds around functions. Good read on the topic: https://www.scribd.com/document/301194560/The-Kingdom-of-Nouns
🌐
StrataScratch
stratascratch.com › blog › mastering-python-class-methods-a-practical-guide
Mastering Python Class Methods: A Practical Guide - StrataScratch
April 19, 2024 - This tells Python that this method should be treated as a class method. ... This definition should start with the first parameter named cls. It can also have other parameters to achieve the desired functionality. ... The next step is to enable the class method to use cls to interact with class attributes. You should be able to create ...
🌐
Wikipedia
en.wikipedia.org › wiki › Object-oriented_programming
Object-oriented programming - Wikipedia
2 weeks ago - Some languages like Python don't provide a visibility feature, but developers might follow a convention such as starting a private member name with an underscore. Intermediate levels of access also exist, such as Java's protected keyword, (which allows access from the same class and its subclasses, but not objects of a different class), and the internal keyword in C#, Swift, and Kotlin, which restricts access to files within the same module.