The instantiation process executes the __init__ function method
classSQLHelper:def __init__(self):#Self = S1 Print("helo") deffetch (self, SQL):Pass defCreate (self, SQL):Pass defremove (self, nid):Pass defModify (self, name):Pass#The instantiation process executes the __init__ function methodS1 =SQLHelper ()" "helo" "
Before modification
classSQLHelper:def __init__(self):#Self = S1 Print("helo") Self.hhost="c1.salt.com"Self.uuserane="Alex"self.pwd="123" deffetch (self, SQL):Pass defCreate (self, SQL):Pass defremove (self, nid):Pass defModify (self, name):Pass#The instantiation process executes the __init__ function methodS1 =SQLHelper ()Print(S1.hhost, S1.uuserane, s1.pwd)" "heloc1.salt.com Alex 123" "
After the transformation
classSQLHelper:def __init__(Self, host, username, pwd):#Self = S1 Print("helo") Self.hhost=host Self.uuserane=username Self.pwd=pwddeffetch (self, SQL):Print(SQL)defCreate (self, SQL):Pass defremove (self, nid):Pass defModify (self, name):Pass#The instantiation process executes the __init__ function methodS1 = SQLHelper ("c1.salt.com","Alex","123") S2= SQLHelper ("c2.salt.com","Mike","123456") S1.fetch ("SELECT * from A")" "Heloheloselect * from A" "
Python __init__ Constructors