from dataclasses import dataclass, field
@dataclass
class Cat:
name: str
color: str
weight: int
children: list = field(default_factory=list)
if __name__ == '__main__':
cat = Cat("小猫", "黑色", 20)
cat1 = Cat("小猫", 20 , "黑色")
print(cat)
print(cat1)
# 输出:
# Cat(name='小猫', color='黑色', weight=20, children=[])
# Cat(name='小猫', color=20, weight='黑色', children=[])
大家好,有个疑问,代码中cat1参数位置不对,也可以正常打印不报错,这种是本来就可以还是工具问题呢