The use of the isinstance of the built-in function in Python

Source: Internet
Author: User

This morning to learn isinstance, a little understanding, on the record (do not know right)

Syntax: Isinstance (Object,type)

function: to determine whether an object is a known type.

Its first argument (object) is the second parameter (type) is the type name (int ...). Or a list of type names ((int,list,float) is a list ). Its return value is Boolean (True or flase).

Returns true if the type of the object is the same as the type of parameter two. If parameter two is a tuple, returns true if the object type is the same as one of the type names in the tuple.

Here are two examples:

Example One

>>> A = 4
>>> isinstance (A,int)
True
>>> isinstance (A,STR)
False
>>> Isinstance (A, (str,int,list))
True

Example Two

>>> a = "B"
>>> isinstance (A,STR)
True
>>> isinstance (A,int)
False
>>> Isinstance (A, (int,list,float))
False
>>> Isinstance (A, (INT,LIST,FLOAT,STR))
True

The use of the isinstance of the built-in function in Python

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.