Python--Tool class method

Source: Internet
Author: User

Python commonly used methods are generally built-in functions, or inherited from the method of object, is said to be a tool class method, but I sometimes encounter some problems, some methods can be like a tool to view certain information, more useful, so I summed up some methods, on behalf of my own views, Interested friends to see-see, together with the exchange, the new discoveries will be written here.

1,id () View the memory address of an object, typically used to analyze two objects is not a thing '

A=[1,2,3,4]b={"a": +, "B": 2}print (ID (a)) print (ID (b))

2,dir () View parameters ' properties and Executable methods

Class Foo ():    a=100    def __init__ (self,name,age):        self.name=name        self.age=age    def fun01 (self):        Pass    def fun02 (self):        passobj=foo ("Zhangsan") Print (dir (Foo)) print (dir (obj))

3,type () View the data type of an object

A=[1,2,3,4]b={"a": "B": 2}c= "ssdkd" Print (Type (a)) print (type (b)) print (type (c))

  

4,sys.path () When importing the module to see if a module can be imported, if the module can be imported in all of the output of the road, or to manually add the path

5, class. __mro__ to see the inheritance of a classic class, the default is to follow the C3 algorithm, the general eye can be seen, no eggs, but particularly complex inheritance will not be able to do, you have to use it

Class A ():    passclass B (a):    passclass C (B):    passclass D (C):    passprint (d.__mro__)

  

  

  

Python--Tool class method

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.