classes python code code example
Example 1: declare class python
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
Example 2: How to make a new class in python
class Fruits():
def __init__(self, name, colour, taste):
self.name = name
self.colour = colour
self.taste = taste
fruit1 = Fruits(apple, red, sweet)
print(fruit1.name)
print(fruit1.colour)
print(fruit1.taste)