class py 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 in python
class Person:
"This is a person class"
age = 10
def greet(self):
print('Hello')
print(Person.age)
print(Person.greet)
print(Person.__doc__)
Example 3: classes in python
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John",
36)
print(p1.name)
print(p1.age)