首页 > 解决方案 > python 使用 super() 显示所有属性

问题描述

@dataclass
class vehicle():
    attributex: int
    attributey: int
    attributez: int
    
@dataclass
class Bus(vehicle):
    attribute1: int
    attribute2: int
    attribute3: int
                   
@dataclass
class Bike(vehicle):
    attribute4: int
    attribute5: int
    attribute6: int

现在我想要一个代码来显示所有这样的属性:

>>> bike1 = Bike(1,2,3,4,5,6)
>>> print(bike1.show_data)
attributex: 1 attributey: 2 attributez: 3 attribute1: 4 attribute2: 5 attribute3: 6 

谢谢你的帮助。

标签: pythonclassattributes

解决方案


推荐阅读