【问题标题】:Python : getting class type only?Python:只获取类类型?
【发布时间】:2013-11-29 23:53:23
【问题描述】:

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

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

例如:

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

谢谢,

【问题讨论】:

    标签: python class python-3.x types


    【解决方案1】:

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

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

    【讨论】:

    • >> 你也可以这样做 >> b
    • @ShikharDua - 不,他想要这个名字。只做>> b 会产生<class 'float'>
    • 其实我都用过python和Ipython。前者给出 后者产生 'float'
    猜你喜欢
    • 2016-03-23
    • 2021-10-15
    • 1970-01-01
    • 2019-05-29
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    相关资源
    最近更新 更多