Subscribe Us

OOPS | Swlf method | In Python| 2023

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 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

 

Output:

My name is Simran and I'm 20 years old.

Post a Comment

0 Comments