Python Forum
Python inner classes inheritance from parent class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python inner classes inheritance from parent class
#3
(Apr-21-2025, 07:43 PM)Axel_Erfurt Wrote: Why 2 classes?

class Numbers:
    def __init__(self,a,b):
        self.sum = a + b
        self.prod = a * b
 
twoNumbers = Numbers(5,4)
 
print(twoNumbers.sum, twoNumbers.prod)

Thank you for the offered solution, but I am actually writing a more sophisticated code and I need to access the parent class attributes (not methods) within the child class. The snippet I posted is just an illustration of what I am trying to achieve. My actual code is very big and not suitable for posting here.
Reply


Messages In This Thread
RE: Python inner classes inheritance from parent class - by Abedin - Apr-22-2025, 12:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Classes rob101 4 1,694 Feb-05-2024, 06:51 PM
Last Post: rob101
  super() and order of running method in class inheritance akbarza 7 2,654 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
Question [solved] Classes, assign an attributes to a class not to instances.. SpongeB0B 4 2,136 May-20-2023, 04:08 PM
Last Post: SpongeB0B
  Understanding Python classes PythonNewbee 3 2,300 Nov-10-2022, 11:07 PM
Last Post: deanhystad
Sad Python classes PythonNewbee 4 2,257 Nov-09-2022, 01:19 PM
Last Post: deanhystad
  Child class inheritance issue eakanathan 3 2,323 Apr-21-2022, 12:03 PM
Last Post: deanhystad
  dict class override: how access parent values? Andrey 1 2,671 Mar-06-2022, 10:49 PM
Last Post: deanhystad
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 4,067 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  Inheritance vs Instantiation for Python classes mr_byte31 7 5,772 Oct-14-2021, 12:58 PM
Last Post: mr_byte31
  Understanding Python super() for classes OmegaRed94 1 2,529 Jun-09-2021, 09:02 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020