gpt4 book ai didi

python : getting class type only?

转载 作者:太空宇宙 更新时间:2023-11-03 13:46:09 25 4
gpt4 key购买 nike

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

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

例如:

a = float("4.67")
b = type(a)
print(b)

谢谢,

最佳答案

您可以为此使用 .__name__ 属性:

>>> a = float("4.67")
>>> b = type(a)
>>> b.__name__
'float'
>>>

关于 python : getting class type only?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20020548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com