diff --git a/Python Classes/Class Overriding method.py b/Python Classes/Class Overriding method.py new file mode 100644 index 0000000..6c43e13 --- /dev/null +++ b/Python Classes/Class Overriding method.py @@ -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() + + \ No newline at end of file diff --git a/Python Classes/Python Inheritance.py b/Python Classes/Python Inheritance.py new file mode 100644 index 0000000..9eb8db5 --- /dev/null +++ b/Python Classes/Python Inheritance.py @@ -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() + + \ No newline at end of file diff --git a/Python Classes/Static Method in class.py b/Python Classes/Static Method in class.py new file mode 100644 index 0000000..52cb394 --- /dev/null +++ b/Python Classes/Static Method in class.py @@ -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 \ No newline at end of file diff --git a/Python Classes/Supper Class Constructor.py b/Python Classes/Supper Class Constructor.py new file mode 100644 index 0000000..1da5b14 --- /dev/null +++ b/Python Classes/Supper Class Constructor.py @@ -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() + + \ No newline at end of file diff --git a/Python Classes/classes and objects in python.py b/Python Classes/classes and objects in python.py new file mode 100644 index 0000000..7c8d883 --- /dev/null +++ b/Python Classes/classes and objects in python.py @@ -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() + + + \ No newline at end of file diff --git a/Python Classes/python Claass 4.py b/Python Classes/python Claass 4.py new file mode 100644 index 0000000..ddd518a --- /dev/null +++ b/Python Classes/python Claass 4.py @@ -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") + + \ No newline at end of file diff --git a/Python Classes/python classes 5.py b/Python Classes/python classes 5.py new file mode 100644 index 0000000..fc3534d --- /dev/null +++ b/Python Classes/python classes 5.py @@ -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 \ No newline at end of file