首页 > 解决方案 > very weird question for object nesting of python

问题描述

class Node:
    def __init__(self,c):
        self.c = c
    c = ""
    times = 0
    next = [None]*26
    
root = Node('x')
root.next[0] = Node('x')
print(root.next[1])
root.next[0].next[1] = Node('x')
print(root.next[1])

The answer:

None

<__main__.Node object at 0x0000018F31644670>

When python excute root.next[0].next[1] = Node('x') ,Node('x') also is written into root.next[1] . It is weird, why it happens?

标签: python

解决方案


推荐阅读