-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created new folder for python practice, practiced objects
- Loading branch information
Showing
3 changed files
with
106 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,15 @@ | ||
#!/usr/bin/python3 | ||
# person_class.py | ||
# 2018-07-28 | ||
# Purpose: To review python Object Oriented Programming | ||
|
||
# To run an interactive python shell of this file add the -i tag when running | ||
# EX: python3 -i class.py | ||
|
||
|
||
class Person: | ||
|
||
age = 20 | ||
|
||
def name(self, name): | ||
return list(name) |
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,45 @@ | ||
#!/usr/bin/python3 | ||
# person_class.py | ||
# 2018-07-28 | ||
# Purpose: To review python Object Oriented Programming | ||
|
||
# To run an instance of this file in a interactive python shell add the -i tag when running | ||
# EX: python3 -i class.py | ||
|
||
class Food: | ||
def __init__(self, dish_name, place_origin, is_healthy): | ||
self.dish_name = dish_name | ||
self.place_origin = place_origin | ||
self. is_healthy = is_healthy | ||
print('creating food object') | ||
|
||
def getDishName(self): | ||
return self.dish_name | ||
|
||
def getOrigin(self): | ||
return self.place_origin | ||
|
||
def getIsHealthy(self): | ||
return self.is_healthy | ||
|
||
def __del__(self): | ||
print('destroying food object') | ||
|
||
class Pizza(Food): | ||
def __init__(self, toppings, size, price): | ||
Food.__init__(self, 'Pizza', 'Italy', False) | ||
self.toppings = toppings | ||
self.size = size | ||
self.price = price | ||
|
||
def getToppings(self): | ||
return self.toppings | ||
|
||
def getSize(self): | ||
return self.size | ||
|
||
def getPrice(self): | ||
return self.price | ||
|
||
|
||
large_pepperoni_pie = Pizza(['pepperoni', 'cheese'], 'Large', 17.99) |
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,46 @@ | ||
#!/usr/bin/python3 | ||
# person_class.py | ||
# 2018-07-28 | ||
# Purpose: To review python Object Oriented Programming | ||
|
||
# To run an instance of this file in a interactive python shell add the -i tag when running | ||
# EX: python3 -i class.py | ||
|
||
class Animal: | ||
def __init__(self, name, species): | ||
self.name = name | ||
self.species = species | ||
|
||
def getName(self): | ||
return self.name | ||
|
||
def getSpecies(self): | ||
return self.species | ||
|
||
def __del__(self): | ||
#Destroys instance of class | ||
print('Animal Destroyed :(') | ||
|
||
class FourLegs: | ||
def hasLegs(self): | ||
return 4 | ||
|
||
#Dog Class inherits the Animal and FourLegs class methods and properties | ||
class Dog(Animal, FourLegs): | ||
|
||
def __init__(self, name, breed, is_big): | ||
Animal.__init__(self, name, 'Dog') | ||
self.breed = breed | ||
self.is_big = is_big | ||
print('Creating DOGO: ' + self.getName()) | ||
|
||
#Overide getSpecies method inherited from the Animal class | ||
def getSpecies(self): | ||
return self.species, self.breed | ||
|
||
def getis_big(self): | ||
return self.is_big | ||
|
||
|
||
#Intialize a instance of the Animal class | ||
kevin = Dog('Kevin', 'Shiba Inu', False) |