在Python
属性。 However, a simpler and more accessible method is utilizing the name attribute of the class.
Using the name Attribute of the Class
The name attribute provides the name of the class associated with an object instance.可以通过以下语法直接访问此属性:This example returns "count," indicating that the object instance x was created from the count class within the itertools module.
Compatibility with Python Versions
type(x).__name__name
attribute method is compatible with both Python 2 and Python 3. In Python 2,此方法仅适用于新样式的类。如果您的代码仍然使用旧式类,则可以使用以下替代方案:[&& && && &&华级。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3