【问题标题】:Print only name of a class in Python [duplicate]仅打印Python中类的名称[重复]
【发布时间】:2019-03-15 02:22:45
【问题描述】:

我正在学习 Python 3。

我的代码

numbers = [1, 2]
print( type( numbers[0] ))

输出

<class ‘int’>

如何只打印

‘int’

int

【问题讨论】:

    标签: python


    【解决方案1】:

    您可以使用类型中的__name__ 属性。

    >>> type(5).__name__
    'int'
    

    或者不使用type built-in:

    >>> (5).__class__.__name__
    'int'
    

    【讨论】:

    • 感谢您对 Python 新手(第 3 天)的帮助。
    • 不客气。
    猜你喜欢
    • 1970-01-01
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-31
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    相关资源
    最近更新 更多