在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
表示字符串類型等。