- Class in blueprint, design of any object. suppose you want to build a house for yourself. For building house you need plan, design and blueprint of the house to build the house. In this case plan, design and blueprint is class and Physical built House is Object.
- Class represent properties(Attributes) and action(behavior) of object.
- Properties are represented by variables and actions are represented by methods.
- So class contains both variables and methods.
How to create class in Python
Class in created using 'class' keyword in Python.
Syntax
class className
Example:
class Car:
def __init__(self):
print('Inside constructor')
def m1(self):
print('Inside method')
- In this examples Car is name of class and m1 is method name.
Syntax of Object creation in Python
reference variable = className()
- In above example we can create object of Car class-
Audi = Car()
nice post.
ReplyDeletepython online training in hyderabad
python online training hyderabad