在Python中,可以使用type()函数来鉴别一个数据的类型。例如:

a = 5
print(type(a))   # 输出<class 'int'>

b = 3.14
print(type(b))   # 输出<class 'float'>

c = "hello"
print(type(c))   # 输出<class 'str'>

d = True
print(type(d))   # 输出<class 'bool'>

在这个例子中,我们分别定义了一个整数、一个浮点数、一个字符串和一个布尔值,并使用type()函数来输出它们的类型。


原文地址: http://www.cveoy.top/t/topic/eO44 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录