Python standard library: Built-in function type (object)

Source: Internet
Author: User

Type (object)

Type (name, bases, Dict)

This function is the type object that returns the object. When there is only one argument to object, the type object is returned directly. If you just want to determine whether an object belongs to an object of a class, you can use the isinstance () function, which does not require the return type object of this function, because it does not return the type object of the base class when there is an inheritance relationship.

When there are three parameters, name is the name of the class;bases is the tuple of the base class;dict is a namespace variable defined within 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 resulting output is as follows:

<class ' list ' >

<class ' list ' >

<class ' Dict ' >

<class ' __main__. Foo ' >

Cai Junsheng qq:9073204 Shenzhen


Python standard library: Built-in function type (object)

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.