Facebook PixelPython OOPS | Python Tutorial | CodeWithHarry

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 = "Simran"
    age = 20

Creating an Object:

Now create an object of the class.

Example:

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

Now we can print values:

Example:

class Details:
    name = "Simran"
    age = 20
 
obj1 = Details()
print(obj1.name)
print(obj1.age)

Output:

Simran
20