LEARNING PYTHON RESERVED init METHOD!!

in #coding4 years ago
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

Sort:  

Thanks for sharing your creative and inspirational post!



This post got curated by our fellow curator @tibfox and you received a 100% upvote from our non-profit curation service!

Join the official DIYHub community on steem and show us more of your amazing work!

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.029
BTC 66066.52
ETH 3291.81
USDT 1.00
SBD 2.70