对于同 款自行车而言,它们的组成结构都是一样的,如 架、 轮和脚踏板 Python 可以定义这个自行车的类:
class Bike: compose = ['frame','wheel','pedal'] my_bike = Bike() you_bike = Bike() print(my_bike.compose) print(you_bike.compose)输出:
['frame', 'wheel', 'pedal']
['frame', 'wheel', 'pedal']
对于同 款自行车来说,有些顾客 回去后会改造下 如加 车筐可以放东西等
class Bike: compose = ['frame','wheel','pedal'] my_bike = Bike() my_bike.other = 'basket' print(my_bike.other)输出:
basket