__init__()

Last updated:9/17/2020 7:43:49 AM

1 Answers

Prakash nidhi Verma
Prakash nidhi Verma

The __init__() Function:

classes and objects in their simplest form are not really useful in real life applications. It's a built-in __init__() function. 

Example :        

Use the __init__() function to assign values for name and age:

class Person: 
  def __init__(self, name, age):
    self.name = name
    self.age = age
p1 = Person('Prakash', 19)
print(p1.name)
print(p1.age)

Answer