Python Opps Concepts: class and Object - Class and Objects in Python

Python Opps: class and Object

Python Opps Concepts : Class and Object

What is a Class and Objects in Python?

Class: The class is a user-defined data structure that binds the data members and methods into a single unit. Class is a blueprint or code template for object creation. Using a class, you can create as many objects as you want

Object: An object is an instance of a class. It is a collection of attributes (variables) and methods. We use the object of a class to perform actions. 

#print name and age input from user using python object and class 

EX:

class person:

    name=input("enter name")

    age=input("enter age")

    def __init__(self,name,age):

        self.name=name

        self.age=age

    def greet(self):

        #print("name ",self.name,"age",self.age)

        print(f"{self.name} is {self.age} years old")

a=person(person.name,person.age)

a.greet()


No comments:

Post a Comment

Latest Post

How to Generate Barcode and QR code For Our Products

 మీ products కి barcode / QR code generate చేయాలంటే OPTION 1: ONLINE (No Coding – Quick) Best for small shops / beginners 👉Free websites: T...