Creating a Class

In 
Python, 
the 
keyword 
"class"
 
is 
used 
to 
define 
a 
class. 
All 
the 
class 
methods
 
and 
attributes
 
under 
a 
class 
need 
to 
be 
indented
.
class class_name:
    attributes
    def function_name():
object_name = class_name(attributes)
class Car:
    mfg_year = 2021
#this attribute will not change for the objects, so we can initialize it here
    def start(self):
        print("Car started")

Methods of a class

A 
'self'
 
argument 
is 
passed 
when 
a 
method 
is 
created. 
It 
is 
used 
to 
link
 
an 
object 
of 
the 
class 
to 
the 
methods 
of 
that 
class.
The 
name 
of 
the 
object 
is 
passed 
as 
"self"
.

Constructor

The 
special 
method 
with 
the 
name 
"
__init__
" 
is 
the 
class 
Constructor
. 
Whenever 
an 
object 
is 
created, 
this 
method 
is 
automatically 
called 
by 
default, 
and 
you 
can 
initialize
 
the
 
attributes
 
inside 
the 
constructor, 
as 
different 
objects 
can 
have 
different 
attributes.
class Class_Name:
    def __init__(self, attribute_1, attribute_2):
        self.attribute_1 = attribute_1
        self.attribute_2 = attribute_2
class Car:
    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)