溫馨提示×

python如何獲取變量類型

小億
128
2024-05-28 20:01:07
欄目: 編程語言

在Python中,可以使用type()函數(shù)來獲取一個變量的類型。示例如下:

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

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

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

type()函數(shù)將返回變量的類型,例如int表示整數(shù)類型,float表示浮點數(shù)類型,str表示字符串類型等。

0