Python--type () Create class

Source: Internet
Author: User

Today I am a long knowledge, I am a Python rookie, has always been that type (a) can return the type of a, but do not know that type can also be used to create class, this experience is to describe how to create a class with the type (), and how to set the properties of the class.

    1. We use the type to create an empty class: There is only one name, nothing else, and its parameter format is: Type (class_name,bases,dic)

    2. Let's use type to see the type of CLS we create:

    3. View the name of the CLS

    4. If we create a class with a familiar inheritance, it is the same as the CLS:

    5. Of course, we can set the properties of any other class by using the parameter dic, for example:

    6. CLS2 now has more properties than CLS __doc__,__module__

The type of a ——————————————————————————— type () ————————————————————————————

IDLE 2.6. 6
>>> type(None)
<type ' Nonetype '>

>>> type(False)
<type ' bool '>

>>> type(123)
<type ' int '>

>>> type(0.1)
<type ' float '>

>>> type(0L)
<type ' Long '>

>>> type(0.0+0.1j)
<type ' complex '> #复数

>>> type ("Markro")
<type ' str '>

>>> type(["Markro","loverobey.blog.163.com"])
<type ' list '> #列表

>>> type (("A", "B")
<type ' tuple '> #元组

>>> type ({' X ': 1})
<type ' dict '> #字典

>>> type (Type ("Markro"))
<type ' type '>

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.