Python Forum
Inheritance vs Instantiation for Python classes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inheritance vs Instantiation for Python classes
#1
I know the meaning of Instantiation and Inheritance.
I can inherit a class and use it methods and attributes.
I also can instantiate a class and still can use the same methods and attributes !!

I am just wondering why there exists two solutions for the same problem.
is there any advantage of using one over the other (memory, speed, ..)

Inheritance:
class A:        # define your class A
pass
class B:         # define your class B
pass
class C(A, B):   # subclass of A and B
Instantiation:
class Foo():
        def __init__(self,x,y):
            print (x+y)
f = Foo(3,4)
Reply


Messages In This Thread
Inheritance vs Instantiation for Python classes - by mr_byte31 - Sep-23-2021, 12:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Classes rob101 4 527 Feb-05-2024, 06:51 PM
Last Post: rob101
  Understanding Python classes PythonNewbee 3 1,183 Nov-10-2022, 11:07 PM
Last Post: deanhystad
Sad Python classes PythonNewbee 4 1,046 Nov-09-2022, 01:19 PM
Last Post: deanhystad
  Understanding Python super() for classes OmegaRed94 1 1,828 Jun-09-2021, 09:02 AM
Last Post: buran
  Python classes Python_User 15 4,857 Aug-04-2020, 06:57 PM
Last Post: Python_User
  XlsxWriter and Python inheritance aquerci 1 2,494 May-05-2020, 09:36 AM
Last Post: buran
  Python Classes leodavinci1990 1 2,079 Nov-27-2019, 07:25 AM
Last Post: buran
  How inheritance works in Python ARV 1 1,832 Oct-03-2019, 03:06 PM
Last Post: Larz60+
  Problems with inheritance with classes internetguy 3 2,589 Jul-04-2019, 11:59 AM
Last Post: metulburr
  Unexpected Output using classes and inheritance langley 2 1,943 Jul-04-2019, 09:33 AM
Last Post: langley

Forum Jump:

User Panel Messages

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