In Python, variables are just names for objects. An object can have zero or more names. So if you have a simple class like:
class Node:
def __init__(self,value):
self.value = value
self.next = None
You can create nodes and "name" the next one in the list:
>>> a = Node(1)
>>> b = Node(2)
>>> a.next = b # a.next is another name for b
>>>
>>> b.value
2
>>> a.next.value
2
>>> b.value = 5 # change b
>>> a.next.value # a.next another name for b
5
Internally, at least in CPython, The names refer to PyObject*
instances, which are pointers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.