【发布时间】:2021-01-13 19:16:56
【问题描述】:
如果我在 while 循环中将“last.next”替换为“last”,为什么会出现错误(AttributeError: 'NoneType' object has no attribute 'next')。谢谢您的帮助
1.
2.
3. def append_right(self,data):
4. new_node = Node(data)
5. last = self.head
6. if self.head is None:
7. self.head = new_node
8. return
9. while last:
10. last = last.next
11. last.next = new_node
12.
【问题讨论】:
-
当你的while循环退出时,最后一个将为None。