python class build method 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: python class
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)
p1 = Person("barry", 50)
p1.myfunc()
Example 3: class python
class MyClass(object):
def __init__(self, x):
self.x = x