How to see data type in python

(*-*)浩
Release: 2019-07-09 10:17:54
Original
4638 people have browsed it

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)
Copy after login

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;>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!