头部如何代表第一个对象
How the head is representing the first object
class Element(object):
def __init__(self, value):
self.value = value
self.next = None
class LinkedLIst(object):
def __init__(self, head= None):
self.head = head
e1 = Element(1)
ll = LinkedLIst(e1)
print(ll.head) #pointing towards e1 object
print(ll.head.value) # printing the value as 1 of e1 object
在这段代码中,head 是如何表示 e1 值的,因为我在任何地方都没有提到 head 是第一个对象
感谢您的评论我得到了答案
因为我已经将 class 定义为 class LinkedLIst(object):
在调用 ll = LinkedLIst(e1) 时,如果没有参数,则 e1 通过 init 方法传递给 head,然后 head = None。
感谢您的帮助。
class Element(object):
def __init__(self, value):
self.value = value
self.next = None
class LinkedLIst(object):
def __init__(self, head= None):
self.head = head
e1 = Element(1)
ll = LinkedLIst(e1)
print(ll.head) #pointing towards e1 object
print(ll.head.value) # printing the value as 1 of e1 object
在这段代码中,head 是如何表示 e1 值的,因为我在任何地方都没有提到 head 是第一个对象
感谢您的评论我得到了答案
因为我已经将 class 定义为 class LinkedLIst(object):
在调用 ll = LinkedLIst(e1) 时,如果没有参数,则 e1 通过 init 方法传递给 head,然后 head = None。
感谢您的帮助。