By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,583 Members | 3,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,583 IT Pros & Developers. It's quick & easy.

Python subclass function call

P: 7
My questions is regarding subclasses in Python.

For example, if I have the following code.

Expand|Select|Wrap|Line Numbers
  2. class Myclass:
  3.       def __init__(self, input)
  4.           self.input = input
  6.       def function(self, input)
  7.           return output
  9. class MySubclass(Myclass)
  10.       def function(self, input)
  11.           return output
The question is how would you access the function in the sub class as opposed to the one in the base class?
Nov 19 '18 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 621
First, your program produces many errors, the variable, "output", has not been declared, syntax error=no colon in several places, and at least on more. Once you override a method, it no longer exists, unless to call it explicitly (from an instance of MyClass in this class.) Search for method overriding/overloading for a detailed answer like
Nov 19 '18 #2

P: 7
Thank you for the response and link provided. I apologize because the code entered in the post was just example code. It does not have functionality. I'm trying to better understand the significance of subclasses and what can be done with them. The link helped clarify some things.
Nov 20 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.