Python built-in function (--isinstance)

Source: Internet
Author: User

English documents:

isinstance(object, classinfo)

Return true if the object argument is an instance of the classinfo argument, or of a (direct, indirect o R Virtual) subclass thereof. If Object is a object of the given type, the function always returns FALSE. If ClassInfo is a tuple of type objects (or recursively, and other such tuples), return True if the object is an Instance of any of the types. If ClassInfo is a type or a tuple of types and such tuples, a TypeError exception is raised.

Description

1. The function function is used to determine whether an object is an instance of a type object, which represents the object to be inspected, and the Calssinfo parameter represents the type object.

2. Returns true if the object parameter is an instance of the ClassInfo type (or the direct, indirect, virtual subclass of the ClassInfo class object).

>>> isinstance (1, int) True>>> isinstance (1, str) False#Definitions 3 Categories: C Inherits B,b inheritance a>>>classA:Pass>>>classB (A):Pass>>>classC (B):Pass>>> A =A ()>>> B =B ()>>> C =C ()>>> isinstance (A,a)#Direct InstanceTrue>>>Isinstance (A, b) False>>> isinstance (B,a)#sub-class instancesTrue>>> isinstance (C,a)#Grandson Class ExampleTrue

3. Always return FALSE if the object parameter is passed in to a type.

>>> isinstance (str,str) false>>> isinstance (bool,int) False

4. If the ClassInfo type object is a tuple of multiple type objects, returns True if the Object object is an instance of any type object in the tuple, otherwise false is returned.

>>> Isinstance (A, (b,c)) False>>> isinstance (A, (a,b,c)) True

5. If the ClassInfo type object is not a type object or a tuple of multiple type objects, an error (TYPEERROR) will be made.

>>> isinstance (A,[a,b,c]) Traceback (most recent):  "<pyshell#23>  " in<module>    or tuple of types

Python built-in function (--isinstance)

Related Article

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.