Parametric forms Manual Literal translation examples expand reading
Parameter Form type (object) type (name, bases, dict) Manual
With one argument, return the type of object. The return value was a type object and generally the same object as returned by object.__class__.
The isinstance () built-in function is recommended for testing the type of object, because it takes to subclasses into Acco Unt.
With three arguments, return a new type object. This is essentially a dynamic form of the class statement. The name string is the class name and becomes the __name__ attribute; The bases tuple itemizes the base classes and becomes the __bases__ attribute; And the Dict dictionary is the namespace containing definitions for class and are copied to a standard dictionary to B Ecome the __dict__ attribute. For example, the following two statements create identical type objects:
>>>
>>> class X:
... A = 1
...
>>> x = Type (' x ', (object,), Dict (a=1)
Also Type Objects. literal translation
Returns the type of object when a single parameter is a type object, usually the same as a object.__class__ return object.
For test object types, isinstance () built-in functions are recommended because they can take into account subclasses.
Three parameter returns a new type Object, which is essentially the dynamic form of the class declaration. The name string is the class name, becomes the __name__ property, thebases tuple lists the base class, becomes the __bases__ property, thedict Dictionary is the namespace that contains the class body definition, and copies it to the standard dictionary, which becomes __ Dict__ property. For example, the following two declarations create objects of the same type:
>>>
>>> class X:
... A = 1
...
>>> x = Type (' x ', (object,), Dict (a=1)
See Type Object instance for details
>>> type (object)
<class ' type ' >
>>> type (type)
<class ' type ' >
> >> type (dict)
<class ' type ' >
>>> type (1)
<class ' int ' >
>>> type (int)
<class ' type ' >
>>> type (' 1 ')
<class ' str ' >
>>> type (b ' 1 ')
< Class ' bytes ' >
>>> type (None)
<class ' Nonetype ' >
>>> type (True)
<class ' bool ' >
Expand your reading
Isinstance ()
Type Object