温馨提示×

python中怎么查看数据类型

小亿
84
2024-03-14 15:29:22
栏目: 编程语言

在Python中,可以使用type()函数来查看数据的类型。

例如:

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

y = "Hello"
print(type(y))  # 输出:<class 'str'>

z = [1, 2, 3]
print(type(z))  # 输出:<class 'list'>

通过调用type()函数并传入要查看类型的变量,即可获取该变量的数据类型。

0