In Python, we can create a class by using the keyword “class.” An object gets created from the constructor. This object represents the instance of the class. In Python, we generate classes and instances in the following way:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("Amlendra",28)
print(p1.name)
print(p1.age)
In the above example, we have created a class named Person and using the __init__() we are assigning name and age to the newly created object.
Answer:
In Python, we can create a class by using the keyword “class.” An object gets created from the constructor. This object represents the instance of the class. In Python, we generate classes and instances in the following way:
In the above example, we have created a class named Person and using the __init__() we are assigning name and age to the newly created object.
need an explanation for this answer? contact us directly to get an explanation for this answer