Python Forum
How inheritance works in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How inheritance works in Python
#1
I am beginner to OOPS concepts. I have written small code to understand inheritance concept. But i had a query while writing code. As per Inheritance concept, the derived class inherits properties of base class. In below example I have created two classes with different name but same methods/functions and passed to these classes to derived class. Now here query is how call the myClass1 method in derived class. because it is same method

Can someone help us to understand the concept quickly.

class myClass():
    def method1(self):
        print("Guru99")

class myClass1():
    def method1(self):
        print("Guru991")


class childClass(myClass, myClass1):
    def method2(self):
        print("ChildClass Method1")


def main():
    c2 = childClass()
    c2.method1() # myClass.method1()
    c2.method2()
    # c2.method1() # myClass1.method1()
Reply
#2
see: http://openbookproject.net/thinkcs/pytho...cts_I.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Inheritance vs Instantiation for Python classes mr_byte31 7 2,789 Oct-14-2021, 12:58 PM
Last Post: mr_byte31
  Python Regular expression, small sample works but not on file Acernz 5 2,861 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  "Automate the Boring Stuff with Python" creating a path works but only for CMD promt Milos 2 2,822 Nov-28-2020, 01:08 PM
Last Post: Larz60+
  Works with Curl. Can't get it to work in Python bazcurtis 3 2,499 May-07-2020, 07:47 AM
Last Post: bazcurtis
  XlsxWriter and Python inheritance aquerci 1 2,465 May-05-2020, 09:36 AM
Last Post: buran
  New to Python, How does this lambda expression works? Joshh_33 2 1,998 Mar-26-2020, 03:32 PM
Last Post: Joshh_33
  time.sleep works erratically, a bug in Python? stipcevic 2 3,819 Jan-21-2020, 09:38 PM
Last Post: Marbelous
  [split] What version of python works on Windows Vista? tit 1 6,978 Oct-11-2018, 10:08 AM
Last Post: Larz60+
  code works in python shell, but not in a terminal Pedroski55 5 3,759 Sep-10-2018, 07:10 AM
Last Post: Pedroski55
  Cant run command python in PyCharm, but it works in cmd LevG0r 1 2,781 Sep-09-2018, 06:21 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

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