在Python中,可以使用type()
函数来查看变量的类型。示例如下:
x = 5
print(type(x)) # 输出:<class 'int'>
y = 3.14
print(type(y)) # 输出:<class 'float'>
z = "hello"
print(type(z)) # 输出:<class 'str'>
is_valid = True
print(type(is_valid)) # 输出:<class 'bool'>
在上面的示例中,通过type()
函数将变量传递给它,它将返回变量的类型。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python怎么查看变量类型