Python Object Classes

 

Python OOPS

A class is a blueprint or a template for creating objects while an object is an instance or a copy of the class with actual values. 

 

Creating a Class:

Create a class using the class keyword.


Example:

class Details:
    name = "Maxon"
    age = 26

 

Creating an Object:

Now create object of the class.


Example:

obj1 = Details()
print(obj1.name)
print(obj1.age)

 

Now we can print values:


Example:

class Details:
    name = "Maxon"
    age = 26

obj1 = Details()
print(obj1.name)
print(obj1.age)


Output:

Maxon
26