Global dictionaries don't need keyword global to modify them? [duplicate]
问题 This question already has an answer here : Closed 6 years ago . Possible Duplicate: Why is not the keyword global not required in this case? I wonder why I can change global dictionary without global keyword? Why it's mandatory for other types? Is there any logic behind this? E.g. code: #!/usr/bin/env python3 stringvar = "mod" dictvar = {'key1': 1, 'key2': 2} def foo(): dictvar['key1'] += 1 def bar(): stringvar = "bar" print(stringvar) print(dictvar) foo() print(dictvar) print(stringvar) bar(