租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

python怎么看变量类型,python怎么看变量的数据类型

发布时间:2024-01-19 19:36:58

python怎样看变量类型

在Python中,可使用type()函数来查看变量的类型。示例以下:

x = 5
y = "Hello"
z = [1, 2, 3]

print(type(x))  # <class 'int'>
print(type(y))  # <class 'str'>
print(type(z))  # <class 'list'>

这里的type()函数会返回变量的类型,它返回的是一个类型对象。可以通过使用str()函数将类型对象转换为字符串情势,以便更容易读地显示变量的类型。