Python path-python (object-oriented advanced)

Source: Internet
Author: User

First, the object-oriented Advanced Syntax section

1. Static methods, class methods, property methods

2. Special methods of Class

3. Reflection

Second, exception handling

Third, Socket Development Foundation

First, the object-oriented Advanced Syntax section

  static methods (@staticmethod)

Definition:   only nominal collation management, in fact, in a static method can not access the properties of the class or instance

  

1 classDog (object):2     def __init__(self,name):3Self.name =name4 5 @staticmethod6     defEat (x,s):7         Print("%s is eating%s"%(x,s))8Dog.eat ("DF","fdasf")9"" DF isEating fdasf

  class method (@classmethod)

Definition: class methods can access only class variables and cannot access instance variables

1 classDog (object):2Name ="444"3     def __init__(self,name):4Self.name =name5 6 @classmethod7     defEat (self):8         Print("%s is eating"%(self.name))9 TenD = Dog ("Zhangsan") One d.eat () A"" 444 isEating

  Property Method (@property)

Definition: Turn a method into a static property

1 classDog (object):2     def __init__(self,name):3Self.name =name4 5 @property6     defEat (self):7         Print("%s is eating"%self.name)8 9D = Dog ("Zhangsan")Ten d.eat () One"" TypeError:'Nonetype'Object is  notCallable
1 correct method of invocation2 classDog (object):3     def __init__(self,name):4Self.name =name5 6 @property7     defEat (self):8         Print("%s is eating"%self.name)9 TenD = Dog ("Zhangsan") OneD.eat#eat Not added ()

  Special members and methods of the class

  1, __doc__, print the description of the class information

  

1 classDog (object):2     " "3 Here is the description information4     " "5     def __init__(self,name):6Self.name =name7 8     defEat (self):9         Print("%s is eating"%self.name)Ten  One Print(Dog.)__doc__) A>>> here is a description of the information

2,__module__ and __class__

Python path-python (object-oriented advanced)

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.