Home >Backend Development >Python Tutorial >How to see data type in python

How to see data type in python

(*-*)浩
(*-*)浩Original
2019-06-28 10:05:494686browse

type() function returns the type of object if you only have the first parameter, and the three parameters return the new type object.

How to see data type in python

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 &#39;int&#39;>
>>> type('runoob')
<type &#39;str&#39;>
>>> type([2])
<type &#39;list&#39;>
>>> type({0:'zero'})
<type &#39;dict&#39;>
>>> x = 1         
>>> type( x ) == int    # 判断类型是否相等
True
  
# 三个参数
>>> class X(object):
...     a = 1
...
>>> X = type('X', (object,), dict(a=1))  # 产生一个新的类型 X
>>> X
<class &#39;__main__.X&#39;>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn