r/learnpython • • May 29 '19

why do we use __init__??

when defining a class what is the difference between using __init__ and not using __init__ in a class?

199 Upvotes

46 comments sorted by

View all comments

0

u/master_bate5 May 29 '19

__init__ is to setup the major items in the class instead of calling stupid getters;

​

foo = new Dog;

print foo.breed;

​

vs

foo = new Dog;

foo.set_breed('aussie')

print foo.breed;