Skip to content

Commit

Permalink
Python classes Folder Updated
Browse files Browse the repository at this point in the history
Python is A OOP Langugage.
  • Loading branch information
codeperfectplus committed Jan 24, 2020
1 parent 26b2640 commit 432f747
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Python Classes/Class Overriding method.py
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()


20 changes: 20 additions & 0 deletions Python Classes/Python Inheritance.py
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()


10 changes: 10 additions & 0 deletions Python Classes/Static Method in class.py
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
20 changes: 20 additions & 0 deletions Python Classes/Supper Class Constructor.py
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()


24 changes: 24 additions & 0 deletions Python Classes/classes and objects in python.py
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()



28 changes: 28 additions & 0 deletions Python Classes/python Claass 4.py
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")


27 changes: 27 additions & 0 deletions Python Classes/python classes 5.py
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

0 comments on commit 432f747

Please sign in to comment.