我不明白current = trie
(第2行)的行为。
它是如何分配和附加新值的?
trie = {}
current = trie
word = "hello"
for ch in word:
if ch not in current:
current[ch] = {}
current = current[ch]
current['*'] = True
print(trie)
print (current)
给出输出:
{'h': {'e': {'l': {'l': {'o': {'*': True}}}}}}
{'*': True}
但是我期望trie
的值不会改变。
b = 6
a = b
a += 1
print (a, b)
给出7 6.为什么b仍然指向6?