python - 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?
解决方案
推荐阅读
- android - 如何调试“java.lang.NoSuchMethodError”?
- ios - 如何编写一个接受任何符合 Codable 的对象的函数
- html - 如果在同一页面中多次调用浏览器会加载相同的图像文件吗?
- java - 桌面应用程序的 Java 自动化部署
- python - 创建函数中的问题
- objective-c - 来自 Xib 的基于视图的 NSTableView
- excel - 如何根据表中的一系列值过滤 Power Query?
- javascript - React Material-UI 纯 JavaScript
- php - 选择新图像时如何保存到数据库。如果没有,将旧照片留在数据库中吗?
- r - 如何使用 R 中的引导程序计算标准误差?