有关Python中链表的基本问题 所以这里重要的是head = head.next仅重新分配head而不是curr

让我们指向以下链接列表的第一个元素1-> 2-> 3->空
列表中的每个元素都是一个具有以下属性的Node():val和next

何时:

curr=head
head=head.next
curr.next.val= 1000
#here head.val outputs 1000 : We changed the value of the 2nd node

但是当:

curr=head
head=head.next
curr.next= Node(1000)
#here head.val outputs 2,it seems that the change
#we made in the previous line didn't
#affect the node but rather created a new 'route'.

有人可以解释为什么在第一种情况下我们修改节点值w.r.t head,而在第二种情况下却不修改节点值吗?

谢谢

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...