Class Attributes Python Code Example
Example 1: declare class python # To create a simple class : class Shape : def __init__ ( ) : print ( "A new shape has been created!" ) pass def get_area ( self ) : pass # To create a class that uses inheritance and polymorphism # from another class : class Rectangle ( Shape ) : def __init__ ( self , height , width ) : # The constructor super . __init__ ( ) self . height = height self . width = width def get_area ( self ) : return self . height * self . width Example 2: class python class MyClass ( object ) : def __init__ ( self , x ) : self . x = x Example 3: python object with attributes class Object ( object ) : pass a = Object ( ) a . somefield = somevalue Example 4: python class class Dog ( object ) : def __init__ ( self , name , age ) : self . name = name self . age = age def speak ( self ) : print ( "Hi I'm ...