在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