Object-oriented programming of Python's Basic Learning Code

Source: Internet
Author: User

Class  addrbookentry (object):     ' Address book entry class '      def __init__ (self,nm,ph):         self.name  = nm        self.phone = ph         print  ' created instance for: ',self.name     Def updatephone (SELF,NEWPH):         self.phone = newph         print  ' update phone for: ',self.name     def updatename (self,newname):         self.name =  newname        print  ' update phone for: ', Self.phonejohn = addrbookentry (' Xiewenbin ', ' 13711710490 ') print john.nameprint  John.phonejohn.updatephone (' 18617311540 ') jOhn.updatename (' XWB ') print john.phoneprint john.nameclass empaddrbookentry (AddrBookEntry):      ' Employee address book entry class '     def  __init__ (Self,nm,ph,id,em):         addrbookentry.__init__ (Self, NM,PH)         self.empid = id         self.email = em    def updateemail (SELF,NEWEM):         self.email = newem         print  ' update email address for: ', Self.namejone = empaddrbookentry (' Jone doe ', ' 408-555-1212 ', A, ' [email protected] ') print jone.nameprint jone.phoneprint  Jone.emailjone.updatephone (' 18617311541 ') print jone.phonejone.updateemail (' [email protected] ') print  jone.emailclass hotElroomcalc (object):     ' Hotel room rate calculator '      def __init__ (self,rt,sales=0.084,rm=0.1):         "Hotelroot  calc  default arguments:        sales tax  == 8.5%  and room tax == 10% '          self.salestax = sales        self.roomtax =  rm        self.rootrate = rt     Def cacltotal (Self,days=1):         ' Calculator total;default  to daily rate '         daily = round ( self.rootrate *  (1 + self.roomtax + self.salestax)), 2)          return float (days)  * dailysfo = hotelroomcalc (299) print sfo.cacltotal (3) class  Teststaticmethod (object):     @staticmethod     def foo ():         print  ' Calling static method foo () ' class  Testclassmethod (object):     @classmethod     def foo (CLS):         print  ' Calling class method foo () '          print  ' foo ()  is part of class: ', Cls.__name__class  c (object):     foo = 100print c.foo + 1class myclass ( Object):     ' Myclass class definition '     myversion =  19.0    def showmyversion (self):         print myclass.myversIonmc = myclass () mc.showmyversion () Print dir (Myclass) print myclass.__dict__ "" "class  INSTCT (object):     count = 0    def __init__ (self):         instct.count += 1    def __ Del__ (self):        instct.count -= 1     def howmany (self):         return instct.counta =  INSTCT () B = INSTCT () "" "X = 3 + 0.14jprint x.__class__print [type (GetAttr (X,i))  for i in  (' conjugate ', ' imag ', ' real ')]class foo (object):     x = {2003: ' Poe2 '}foo = foo () print foo.xfoo.x[2004] =  ' Xie ' Print  foo.xprint foo.xdel foo.xprint foo.xprint foo.x


This article is from the "XWB" blog, make sure to keep this source http://xiewb.blog.51cto.com/11091636/1792281

Object-oriented programming of Python's Basic Learning Code

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.