OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to effective do inheritance in python

  • Thread starter Thread starter Yehui He
  • Start date Start date
Y

Yehui He

Guest
Imaging a have a super class and try to do subclass there is a method in superclass I want to overwrite

Code:
class Citizen:
    def step(self):
        statement1
        statement2
        statement3
        statement4 # I want to change this one only
        statement5
        statement6


class Inhabitant(Citizen):
    def step(self):
        statement1
        statement2
        statement3
        new_statement4 
        statement5
        statement6

do I have to copy every statement again? I only want to change statement4. what's the best way to do this?
<p>Imaging a have a super class and try to do subclass there is a method in superclass I want to overwrite</p>
<pre><code>class Citizen:
def step(self):
statement1
statement2
statement3
statement4 # I want to change this one only
statement5
statement6


class Inhabitant(Citizen):
def step(self):
statement1
statement2
statement3
new_statement4
statement5
statement6
</code></pre>
<p>do I have to copy every statement again? I only want to change statement4. what's the best way to do this?</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top