Home >Backend Development >Python Tutorial >How to see data type in python
type() function returns the type of object if you only have the first parameter, and the three parameters return the new type object.
type(): The subclass is not considered to be the parent class (recommended learning: Python video tutorial)
The following is the syntax of the type() method:
class type(name, bases, dict)
Parameters
name -- the name of the class. bases – A tuple of base classes. dict – Dictionary, namespace variables defined within the class.
Return value
One parameter returns the object type, three parameters returns the new type object.
The following shows examples of using the type function:
# 一个参数实例 >>> type(1) <type 'int'> >>> type('runoob') <type 'str'> >>> type([2]) <type 'list'> >>> type({0:'zero'}) <type 'dict'> >>> x = 1 >>> type( x ) == int # 判断类型是否相等 True # 三个参数 >>> class X(object): ... a = 1 ... >>> X = type('X', (object,), dict(a=1)) # 产生一个新的类型 X >>> X <class '__main__.X'>
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to see data type in python. For more information, please follow other related articles on the PHP Chinese website!