-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#Super Class Constructor | ||
|
||
#parent Class | ||
class Animal(): | ||
def __init__(self, name, age): | ||
self.name = name | ||
self.age = age | ||
def speak(self): | ||
print(f"I am {self.name} and I am {self.age} Old.") | ||
|
||
#child class | ||
class Dog(Animal): | ||
def __init__(self, name, age): | ||
super().__init__(name,age) | ||
|
||
def speak(self): # This will Override parents class; | ||
print("I am A Dog") | ||
|
||
#call child class | ||
t = Dog("tyson", 5) | ||
t.speak() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#parent Class | ||
class Animal(): | ||
def __init__(self, name, age): | ||
self.name = name | ||
self.age = age | ||
def speak(self): | ||
print(f"I am {self.name} and I am {self.age} Old.") | ||
|
||
#child class | ||
class Dog(Animal): | ||
def __init__(self, name, age): | ||
self.name = name | ||
self.age = age | ||
self.type = "dog" | ||
|
||
#call child class | ||
t = Dog("tyson", 5) | ||
t.speak() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" Static methods are methods within a class that have no access to anything else in the class (no self keyword or cls keyword). They cannot change or look at any object attributes or call other methods within the class. They can be thought of as a special kind of function that sits inside of the class. When we create a static method we must use something called a decorator. The decorator for a static method is "@staticmethod" """ | ||
|
||
class Myclass: | ||
def __init__(self): | ||
self.x = x | ||
|
||
@staticmethod | ||
def staticmethod(): | ||
return "I Am A Staic Method" | ||
# Staticmethod does not require self PARAMETER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#Super Class Constructor | ||
|
||
#parent Class | ||
class Animal(): | ||
def __init__(self, name, age): | ||
self.name = name | ||
self.age = age | ||
def speak(self): | ||
print(f"I am {self.name} and I am {self.age} Old.") | ||
|
||
#child class | ||
class Dog(Animal): | ||
def __init__(self, name, age): | ||
super().__init__(name,age) | ||
|
||
#call child class | ||
t = Dog("tyson", 5) | ||
t.speak() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
''' | ||
@author : CodePerfectPlus | ||
@python | ||
''' | ||
|
||
|
||
class dog(): | ||
def __init__(self, name, age): | ||
self.name= name | ||
self.age = age | ||
|
||
def speak(self): | ||
print(f"I am {self.name} and my age is {self.age}.") | ||
|
||
one = dog("Tuktuk", 12) | ||
two = dog("Tyson",4) | ||
three = dog("Mike", 5) | ||
|
||
one.speak() | ||
two.speak() | ||
three.speak() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Vechile: | ||
def __init__(self, price, color): | ||
self.color = color | ||
self.price = price | ||
|
||
def fillUPtank(self): | ||
self.gas = 100 | ||
|
||
def emptyTank(self): | ||
self.gas = 0 | ||
|
||
class Truck(Vechile): | ||
def __init__(self, price, color, tires): | ||
super().__init__(price,color) | ||
self.tires = tires | ||
|
||
def beep(self): | ||
print("Honk Honk") | ||
|
||
class Car(Vechile): | ||
def __init__(self, price, color, speed): | ||
super().__init__(price,color) | ||
self.speed = speed | ||
|
||
def beep(self): | ||
print("Beep Beep") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Over Loading Method | ||
|
||
class Point(): | ||
def __init__(self, x=0, y=0): | ||
self.x = x | ||
self.y = y | ||
self.coords = (self.x, self.y) | ||
|
||
def move(self, x, y): | ||
self.x += x | ||
self.y += y | ||
|
||
def __add__(self, other): | ||
return Point(self.x + other.x, self.y+other.y) | ||
|
||
def __sub__(self,other): | ||
return Point(self.x - other.x, self.y- other.y) | ||
|
||
def __mul__(self,other): | ||
return self.x * other.x , self.y * other.y | ||
|
||
p1 = Point(3,4) | ||
p2 = Point(3,2) | ||
|
||
p3 = p1+ p2 | ||
p4 = p1-p2 | ||
p7 =p1*p2 |