Python standard library: built-in function type (object), pythonobject

Source: Internet
Author: User

Python standard library: built-in function type (object), pythonobject

Type (object)

Type (name, bases, dict)

This function is the type object of the returned object. If there is only one parameter object, the type object of the object is directly returned. If you only want to determine whether an object belongs to a class object, you can use the isinstance () function. This function does not need to return type objects for determination, because when there is an inheritance relationship, it does not return the type object of the base class.

When there are three parameters, name is the name of the class, bases is the tuples of the base class, And dict is the namespace variable defined in the class.

Example:

# Type () print (type ([]) print (type ([2]) print (type ({0: 'zero '}) class Foo: x = 1 y = 2 print (type ('foo', (object,), dict (x = 1 )))

The output is as follows:

<Class 'LIST'>

<Class 'LIST'>

<Class 'dict '>

<Class '_ main _. foo'>

 

Cai junsheng QQ: 9073204 Shenzhen


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.