LEARNING PYTHON RESERVED init METHOD!!

Words
42
Reading
1 min
Listen
Play
7y
class Student:
    def __init__(self,first,last,major):
        self.first=first
        self.last=last
        self.major=major
        self.email= first + '.'+ last + '@'+ 'university.edu'
        
stud= Student("Leo","Umesh","Computer")

print(stud.email)

The output of the above program is as follows:

output.png

When you create the first instance of the class i.e. the object, the init method is called and the parameter self is set to the object value.

Run this python code online here

LEARNING PYTHON RESERVED init METHOD!! | Ecency