Python: Class 2--bif built-in functions for classes and objects

Source: Internet
Author: User

1. Inspection and judgment

Issubclass (class, ClassInfo) if the first parameter is a subclass of the second argument, return True, Note:

    • Non-strict (oneself can be considered to be their own subclass);
    • The second parameter can be a tuple of more than one class, with any appropriate, true;
    • Other cases to throw TypeError

Isinstance (object, ClassInfo) checks whether an instance object of the first argument belongs to a class

    • The second parameter can be a tuple of more than one class, with any appropriate, true;
    • Always returns False if the first parameter passed in is not an object type
    • If the second argument is not a class or a tuple consisting of a class object, it throws a TypeError

2, point operation symbol access to object properties, attribute Related:

The Hasattr (object, Name) object has a set property name,name need to be enclosed in quotation marks, otherwise he will think of it as a variable,

GetAttr (object, name [, default]) Gets the name property of the object, if it does not exist, returns the default, if no default is set, it will be thrown if it does not exist attributeerror

    • GetAttr (A, ' B ', ' The property you are accessing does not exist ')

SetAttr (object, name, value) sets the value of the object Name property to a new property if the property does not exist

Delattr (object, name) removes the established property if it is not thrown attributeerror

Property () Setting properties by property

    • X = Property (GetSize, SetSize, delsize) set an X attribute that can manipulate GetSize, setSize, Delsize (write in advance) method
    • X can be used as a calling interface, the method can be changed, such as changing the name, etc., to increase the method.
    • How it works: combining several magical methods

Python: Class 2--bif built-in functions for classes and objects

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.