create an abstract base class with two int attributes That's not really possible in python. An abstract class must have at least one method decorated with @abc.abstractmethod. You can't make an abstract class with just 2 attributes. You should ask your professor to clarify what they want you to do. Answer from Rawing7 on reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › abstract-classes-in-python
Abstract Classes in Python - GeeksforGeeks
Python provides the abc module to define ABCs and enforce the implementation of abstract methods in subclasses. Example: This example shows an abstract class Animal with an abstract method sound() and a concrete subclass Dog that implements it.
Published   September 3, 2025
🌐
Reddit
reddit.com › r/learnpython › abstract class, how to create it properly?
r/learnpython on Reddit: abstract class, how to create it properly?
March 24, 2024 -

I thought I understood what abstract class means but my professor just commented that it wasn't a abstract class. What I did is essentially this:

first instruction: create an abstract base class with two int attributes then derived another class called Hero with a string attribute which stores the title "hero"

from abc import ABC

class Person(ABC):
def __init__(self, height, speed):
self.height = height
self.speed = speed

def walk(self):
//walk method

from person import Person

class Hero(Person):
def __init__(self, height, speed):
super().__init__(height, speed)
self.person_title = "Hero"

was this the right way to do it?

🌐
Python
docs.python.org › 3 › library › abc.html
abc — Abstract Base Classes
class C(ABC): @property @abstractmethod def my_abstract_property(self): ... The above example defines a read-only property; you can also define a read-write abstract property by appropriately marking one or more of the underlying methods as abstract:
🌐
DataCamp
datacamp.com › tutorial › python-abstract-classes
Python Abstract Classes: A Comprehensive Guide with Examples | DataCamp
January 22, 2025 - Python reports a TypeError when a subclass is attempted to be instantiated if it does not override all abstract methods. This stringent enforcement lowers the likelihood of defects and improves code stability by assisting developers in identifying implementation flaws early. It also guarantees that all concrete subclasses follow the abstract class's intended behavior and design. ... class Rectangle(Shape): def __init__(self, width, height): self.width = width self.height = height # Missing area and perimeter implementation # This will raise an error rectangle = Rectangle(5, 10) # TypeError: Can't instantiate abstract class Rectangle with abstract methods area, perimeter
🌐
MakeUseOf
makeuseof.com › home › programming › abstract classes in python: a beginner's guide
Abstract Classes in Python: A Beginner's Guide
September 11, 2021 - This implementation can be accessed in the overriding method using the super() method. import abc class AbstractClass(ABC): def __init__(self, value): self.value = value super().__init__() @abc.abstractmethod def some_action(self): print("This ...
🌐
DEV Community
dev.to › sarahs › abstract-classes-in-python-55mj
Abstract Classes in Python - DEV Community
December 20, 2023 - ... Title:, a space, and then the current instance's title. Author:, a space, and then the current instance's author. Price:, a space, and then the current instance's price. ... from abc import ABCMeta, abstractmethod class Book(object, ...
🌐
Python Course
python-course.eu › oop › the-abc-of-abstract-base-classes.php
20. The 'ABC' of Abstract Base Classes | OOP | python-course.eu
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-4-2bcc42ab0b46> in <module> 2 pass 3 ----> 4 x = DoAdd42(4) TypeError: Can't instantiate abstract class DoAdd42 with abstract methods do_something · We will do it the correct way in the following example, in which we define two classes inheriting from our abstract class:
Find elsewhere
🌐
Python Tutorial
pythontutorial.net › home › python oop › python abstract classes
Python Abstract Class
March 31, 2025 - from abc import ABC, abstractmethod class AbstractClassName(ABC): @abstractmethod def abstract_method_name(self): pass Code language: Python (python)
🌐
CodeFatherTech
codefather.tech › home › blog › create an abstract class in python: a step-by-step guide
Create an Abstract Class in Python: A Step-By-Step Guide
December 8, 2024 - $ python aircraft.py Traceback (most recent call last): File "aircraft.py", line 3, in <module> class Aircraft(ABC): File "aircraft.py", line 10, in Aircraft @property File "/Users/codefathertech/opt/anaconda3/lib/python3.7/abc.py", line 23, in abstractmethod funcobj.__isabstractmethod__ = True AttributeError: attribute '__isabstractmethod__' of 'property' objects is not writable · Let’s also override the constructor in the Jet class: class Jet(Aircraft): def __init__(self, speed): self.__speed = speed def fly(self): print("My jet is flying")
🌐
Medium
medium.com › @mhesty71 › what-i-wish-i-knew-about-init-self-super-and-abstract-classes-7103c8b91128
What I Wish I Knew About __init__, self, super(), and Abstract Classes | by maria siagian | Medium
December 17, 2024 - It acts like a constructor in other programming languages and is used to initialise the object’s attributes. Think of __init__ as the blueprint setup for building a house. When you construct a house (create an object), you decide how many ...
🌐
Towards Data Science
towardsdatascience.com › home › latest › how to use abstract classes in python
How to Use Abstract Classes in Python | Towards Data Science
January 21, 2025 - Some of you might be wondering why we couldn’t just use a normal class (i.e. not inherit from ABC) and raise a NotImplementerError for methods that have not been implemented, like in the example below. class NotAbstractBasicPokemon: def __init__(self, name): self.name = name self._level = 1
🌐
Dive into Python
diveintopython.org › home › learn python programming › classes in python › class super() function
Using of super in Python Class Inheritance and init Method
May 3, 2024 - In this example, super().__init__() calls the __init__() method of class A, the super class of B. This way, both A and B are initialized when a new object of B is created. Another use case is with abstract classes that contain super().__init__() ...
🌐
Python.org
discuss.python.org › typing
Enforcing __init__ signature when implementing it as an abstractmethod - Typing - Discussions on Python.org
December 29, 2024 - Hello. I noticed that Pyright doesn’t check the signatures of abstractmethod implementations when the abstractmethod is __init__(). Here’s an example: from abc import ABC, abstractmethod class AbstractA(ABC): @abstractmethod def __init__(self, x: int, y: int): pass @abstractmethod def do_something(self, z: int, u: int): pass class RealA(AbstractA): def __init__(self, x: int): ## No static type checker error self.x = x def do_something...
🌐
Earthly
earthly.dev › blog › abstract-base-classes-python
Abstract Base Classes in Python - Earthly Blog
July 19, 2023 - The Dog, Cat, and Bird classes indicated in the illustration are concrete subclasses that inherit from the Animal ABC and provide implementations for both abstract methods. To show how they will be implemented we will just implement just one subclass but the idea is the same for the other subclasses. Here is an example of the implementation of the Bird subclass. # animal.py class Bird(Animal): def __init__(self, name): self.name = name def get_name(self): return self.name def make_sound(self): return "Chirp chirp!"
🌐
Python
pythonprogramminglanguage.com › abstract-base-classes
Abstract Base Classes - Python
If you are a Python beginner, then I highly recommend this book. Create an abstract class: AbstractAnimal.
🌐
CodeSignal
codesignal.com › learn › courses › revisiting-oop-concepts-in-python › lessons › understanding-abstract-classes-and-abstract-methods-in-python
Understanding Abstract Classes and Abstract Methods in ...
For example, consider the following ... abstract methods: area and perimeter. Subclasses must implement these methods. The Circle class inherits from Shape, using its constructor to initialize ......
🌐
Scaler
scaler.com › home › topics › abstract class in python
Abstract Class in Python - Scaler Topics
April 9, 2024 - We can use the following syntax to create an abstract class in Python: Here we just need to inherit the ABC class from the abc module in Python. Now, let's take the following example to demonstrate abstract classes:
🌐
Medium
martinxpn.medium.com › abstract-classes-in-python-51-100-days-of-python-94a80879ca6f
Abstract Classes in Python (51/100 Days of Python) | by Martin Mirakyan | Medium
April 10, 2023 - We create a class called MyClass that inherits from ABC, and we decorate the some_method with the @abstractmethod decorator. This tells Python that some_method is an abstract method that needs to be implemented by the derived classes.