Home > Backend Development > Python Tutorial > Python isinstance判断对象类型

Python isinstance判断对象类型

WBOY
Release: 2016-06-16 08:47:38
Original
1615 people have browsed it
复制代码 代码如下:

if (typeof(objA) == typeof(String))
{
//TODO
}

在Python中只需要使用内置的函数isinstance,使用起来非常简单,比如下面的例子:

复制代码 代码如下:

class objA:
pass

A = objA()
B = 'a','v'
C = 'a string'

print isinstance(A, objA)
print isinstance(B, tuple)
print isinstance(C, basestring)
输出结果:
True
True
True
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