I’m new to python and a total noob with programming so bear with.
If I was building show Person class
class Person:
def __init__ (self, Name, Address, Phone, Height, Weight):
self.name = Name
self. Address = Address
self.Phone = Phone
self.Height = Height
self.Weight = Weight
self.PoundserPerInch = int(Height) / int(Weight)
what exactly does the __init__() function do for the code?
The
__init__method is the constructor. It contains code that is run for each object that is created from that class. It contains code to initialize the object in a proper state.In your case, you have a
Personclass which can be used to createPersonobjects. If you would write:it will create a
Personobject with those initial values. The constructor takes the values that you passed and it’ll assign them to the variables of that object. It will also compute a value calledPoundserPerInch.