class node:
def __init__(self,gas,cost,next):
self.gas=gas
self.cost=cost
self.next=next
请问要怎么用循环创建node的实例啊
class node:
def __init__(self,gas,cost,next):
self.gas=gas
self.cost=cost
self.next=next
请问要怎么用循环创建node的实例啊
class node:
def __init__(self,gas,cost,next_ = None):
self.gas=gas
self.cost=cost
self.next_=next_
def __repr__(self):
return f"gas:{self.gas} cost:{self.cost} next_:{self.next_}"
n1 = node("A1", 'D1')
Root = node('A', 'D', n1)
print(n1)
print(Root)
'''--result
gas:A1 cost:D1 next_:None
gas:A cost:D next_:gas:A1 cost:D1 next_:None
'''