Python __init__ Constructors

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.