DEV Community

Durga Pokharel
Durga Pokharel

Posted on

Day 10 of 100DaysOfCode: Object Inheritance

Today is my 10th day of #100daysofcode. I learned more properties of CSS like applied visual Design challenges, Create visual balance using the text-align property, adjusting the width of an element using the width property, adjusting the height of an element using the height property, making use of (strong, U, em , S, hr..) tag from Freecodecamp. I also learned about database on pythoncoursera

I also tried to write code in class on python.

Object Inheritance

Here we have two template. Child template is related to the parent template. Here we add capabilities or extend the capabilities of parent. In the code FootballFan is class which extend the PartyAnimal.It has all the property of PartyAnimal. There are two variables x and name these are attributes also. And we have a constructor that has the name parameter.

After that we have a new calss FootballFan inside the parenthesis we have a name of different class. FootballFan is everything PartyAnimal is plus point we define here. So FootballFan has x instance variable, point inastance variable and name instance variable. And we give object to the PartyAnimal and FootballFan.

class PartyAnimal():
    x = 0
    name = ''
    def __init__(self,z):
        self.name = z
        print(self.name,'constructed')
    def party(self):
        self.x = self.x + 1
        print(self.name,'party count',self.x)

class FootballFan(PartyAnimal):
    points = 0
    def touchdown(self):
        self.points = self.points + 7
        self.party()
        print(self.name,'points',self.points)

s = PartyAnimal('sally')
s.party()

j = FootballFan('jim')
j.party()
j.touchdown()

Enter fullscreen mode Exit fullscreen mode

Day 10 of #100daysofcode and #Python
* More about database on python
* More about CSS properties like applied visual challenges, create a visual balance using the text align property, adjusting the (width, height) of an element using the width property
* Object inheritance pic.twitter.com/pykn6bN4zU

— Durga Pokharel (@mathdurga) January 3, 2021

Top comments (1)

Collapse
 
otumianempire profile image
Michael Otu

You will get there.