0

please help me understand the part under "thispart" comment

class p_table: developer = "Humayun Kamran" #thispart # instance attribute def __init__(self, Z, M, EC): self.Z = Z self.M = M self.EC = EC #thispart H = p_table(1,1, "1s`1") He = p_table(2,4,"1s`2") print("atomic no of H is {}".format(H.Z))

12th Aug 2020, 9:01 PM
humayun kamran
humayun kamran - avatar
4 odpowiedzi
+ 3
This is the init method of the Class. It work like a constructor in other programming languages. It is called when you create an object of that class. In this case it takes the arguments Z M EC and asignes attributes for all arguments.
12th Aug 2020, 9:07 PM
hyred
hyred - avatar
+ 1
self returns the object itself and with sellf.Z you access the attrubute Z of the object which is self points to. I think you should take a python course since this is pretty trivia.
12th Aug 2020, 9:29 PM
hyred
hyred - avatar
0
Okay... But what is "self" here... And why are we assigning self.Z to Z....????
12th Aug 2020, 9:21 PM
humayun kamran
humayun kamran - avatar
0
Okay.. I will
12th Aug 2020, 9:30 PM
humayun kamran
humayun kamran - avatar