Class Attributes

The 
value 
of 
class
 
attributes
 
remain 
the 
same 
for 
all 
the 
objects 
created 
from 
the 
class.
These 
are 
initialized
 
outside 
the 
class 
Constructor
.
class class_name:
    attribute_1 = value #this is a class attribute
    def __init__(self, attribute_2):
        self.attribute_2 = attribute_2 
        #this is an instance attribute
class Car:
    mfg_year = 2021
    def __init__(self, name, color, price):
        self.name = name
        self.color = color
        self.price = price
honda = Car("Honda", "Red", 3500)
print(honda.name, honda.color, honda.price, honda.mfg_year)
Honda Red 3500 2021

Instance Attribute

The 
value 
of 
instance
 
attributes
 
change 
for 
different 
objects 
created 
from 
that 
class. 
They 
are 
initialized 
inside 
the 
class 
Constructor
.
We 
can 
use 
these 
attributes 
by 
using 
the 
object 
name.
object_name.attribute_name

Calling a Method

An 
object 
can 
call
 
the 
methods 
inside 
a 
class.
When 
a 
method 
is 
called, 
the 
object 
name 
is 
sent 
to 
"
self
" 
and 
hence 
the 
instance
 
attributes
 
can 
be 
accessed.
object_name.method_name(arguments)
class Car:
    mfg_year = 2021
    def __init__(self, name, color, price):
        self.name = name
        self.color = color
        self.price = price
    def drive(self, speed):
         print("Driving", self.name, "at", speed, "kmph")
honda = Car("Honda", "Red", 3500)
honda.drive(50)
Driving Honda at 50 kmph