Python example Two

Source: Internet
Author: User

Example 1, constructors

#-*-coding:utf-8-*-Import SYSclassstudent:def __init__ (self,name,age): Self.__name=name Self.__age=Age def getName (self): format="My name is%s My age is%d"%(self.__name,self.__age) print format def __del__ (self): print"del"if__name__=="__main__": Studeng=student ("Chu", *) Studeng.getname ()

Example two: static members and private members

#-*-coding:utf-8-*-Import sysclass  A:    y=2    def __init__ ( Self):        self.x=1        self.__z=1if __name__==" __main__ " :    A=A ()    print a.x    print a.y    print a.__z

Example three:

#-*-coding:utf-8-*-Import sysclass  A:    def prt (self):        "my Name is A"    def reprt (self):        a.prt (self)if __name__=="_ _main__":    a=A ()    a.prt ()    a.reprt ()

Example four: hash lookup of a dictionary

#-*-coding:utf-8-*-Import SYSif__name__=="__main__": Dict={"a":"Apple","b":"Banana","g":"Grape","o":"Orange"} print dict print dict["a"] Dict2={1:"Apple",2:"Banana",3:"Grape",4:"Orange"} print dict2 print dict2[1]

Python example Two

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.