python class cfunctions code example
Example 1: python class
class Animal(object):
def __init__(self, species, price):
self.species = species
self.price = price
def overview(self):
print(f"This species is called a {self.species} and the price for it is {self.price}")
class Fish(Animal):
pass
salmon = Fish("Salmon", "$20")
salmon.overview()
dog = Animal("Golden retriever", "$400")
dog.overview()
Example 2: class python 3
A class is a block of code that holds various functions. Because they
are located inside a class they are named methods but mean the samne
thing. In addition variables that are stored inside a class are named
attributes. The point of a class is to call the class later allowing you
to access as many functions or (methods) as you would like with the same
class name. These methods are grouped together under one class name due
to them working in association with eachother in some way.
class Shape:
def __init__():
print("A new shape has been created!")
pass
def get_area(self):
pass
class Rectangle(Shape):
def __init__(self, height, width):
super.__init__()
self.height = height
self.width = width
def get_area(self):
return self.height * self.width