温馨提示×

python如何获取变量类型

小亿
97
2024-05-28 20:01:07
栏目: 编程语言

在Python中,可以使用type()函数来获取一个变量的类型。示例如下:

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

y = 3.14
print(type(y))  # <class 'float'>

z = "Hello"
print(type(z))  # <class 'str'>

type()函数将返回变量的类型,例如int表示整数类型,float表示浮点数类型,str表示字符串类型等。

0