Python:只获取类类型?

3 python types class python-3.x

在Python中,如果我想在使用命令print时只获取变量类型,我该怎么做?

现在我得到<class 'float'>但我想要'float'.

例:

a = float("4.67")
b = type(a)
print(b)
Run Code Online (Sandbox Code Playgroud)

谢谢,

iCo*_*dez 6

您可以使用以下.__name__属性:

>>> a = float("4.67")
>>> b = type(a)
>>> b.__name__
'float'
>>>
Run Code Online (Sandbox Code Playgroud)