Skip to content

Commit 432f747

Browse files
Python classes Folder Updated
Python is A OOP Langugage.
1 parent 26b2640 commit 432f747

7 files changed

+152
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#Super Class Constructor
2+
3+
#parent Class
4+
class Animal():
5+
def __init__(self, name, age):
6+
self.name = name
7+
self.age = age
8+
def speak(self):
9+
print(f"I am {self.name} and I am {self.age} Old.")
10+
11+
#child class
12+
class Dog(Animal):
13+
def __init__(self, name, age):
14+
super().__init__(name,age)
15+
16+
def speak(self): # This will Override parents class;
17+
print("I am A Dog")
18+
19+
#call child class
20+
t = Dog("tyson", 5)
21+
t.speak()
22+
23+

Python Classes/Python Inheritance.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#parent Class
2+
class Animal():
3+
def __init__(self, name, age):
4+
self.name = name
5+
self.age = age
6+
def speak(self):
7+
print(f"I am {self.name} and I am {self.age} Old.")
8+
9+
#child class
10+
class Dog(Animal):
11+
def __init__(self, name, age):
12+
self.name = name
13+
self.age = age
14+
self.type = "dog"
15+
16+
#call child class
17+
t = Dog("tyson", 5)
18+
t.speak()
19+
20+
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
""" 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" """
2+
3+
class Myclass:
4+
def __init__(self):
5+
self.x = x
6+
7+
@staticmethod
8+
def staticmethod():
9+
return "I Am A Staic Method"
10+
# Staticmethod does not require self PARAMETER
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Super Class Constructor
2+
3+
#parent Class
4+
class Animal():
5+
def __init__(self, name, age):
6+
self.name = name
7+
self.age = age
8+
def speak(self):
9+
print(f"I am {self.name} and I am {self.age} Old.")
10+
11+
#child class
12+
class Dog(Animal):
13+
def __init__(self, name, age):
14+
super().__init__(name,age)
15+
16+
#call child class
17+
t = Dog("tyson", 5)
18+
t.speak()
19+
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'''
2+
@author : CodePerfectPlus
3+
@python
4+
'''
5+
6+
7+
class dog():
8+
def __init__(self, name, age):
9+
self.name= name
10+
self.age = age
11+
12+
def speak(self):
13+
print(f"I am {self.name} and my age is {self.age}.")
14+
15+
one = dog("Tuktuk", 12)
16+
two = dog("Tyson",4)
17+
three = dog("Mike", 5)
18+
19+
one.speak()
20+
two.speak()
21+
three.speak()
22+
23+
24+

Python Classes/python Claass 4.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Vechile:
2+
def __init__(self, price, color):
3+
self.color = color
4+
self.price = price
5+
6+
def fillUPtank(self):
7+
self.gas = 100
8+
9+
def emptyTank(self):
10+
self.gas = 0
11+
12+
class Truck(Vechile):
13+
def __init__(self, price, color, tires):
14+
super().__init__(price,color)
15+
self.tires = tires
16+
17+
def beep(self):
18+
print("Honk Honk")
19+
20+
class Car(Vechile):
21+
def __init__(self, price, color, speed):
22+
super().__init__(price,color)
23+
self.speed = speed
24+
25+
def beep(self):
26+
print("Beep Beep")
27+
28+

Python Classes/python classes 5.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Over Loading Method
2+
3+
class Point():
4+
def __init__(self, x=0, y=0):
5+
self.x = x
6+
self.y = y
7+
self.coords = (self.x, self.y)
8+
9+
def move(self, x, y):
10+
self.x += x
11+
self.y += y
12+
13+
def __add__(self, other):
14+
return Point(self.x + other.x, self.y+other.y)
15+
16+
def __sub__(self,other):
17+
return Point(self.x - other.x, self.y- other.y)
18+
19+
def __mul__(self,other):
20+
return self.x * other.x , self.y * other.y
21+
22+
p1 = Point(3,4)
23+
p2 = Point(3,2)
24+
25+
p3 = p1+ p2
26+
p4 = p1-p2
27+
p7 =p1*p2

0 commit comments

Comments
 (0)