One - One Code All

Blog Content

python判断变量的数据类型的两种方法

Python   2008-01-16 20:12:28

Python判断变量的数据类型的两种方法

Python中的数据类型有数字、字符串,列表、元组、字典、集合等。有两种方法判断一个变量的数据类型

1、isinstance(变量名,类型)
a = isinstance(a, int)

2、通过与其他已知类型的常量进行对比

a = type(a)  ==  type(1)


上一篇:打印PYTHONPATH
下一篇:python中float转为decimal

The minute you think of giving up, think of the reason why you held on so long.