@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2852 / 12833)
There are examples of ʻid () and
global`.
Reference: id (object) Reference: global
I've tried.
http://ideone.com/7ZBN92
animal = 'dog'
def my_func_local():
animal = 'cat'
print(id(animal))
def my_func_global():
global animal
animal = 'wyvern'
print(id(animal))
print(id(animal))
my_func_local()
print(animal)
my_func_global()
print(animal)
run
47889501431096
47889502846848
dog
47889501431208
wyvern
I thought dog and wyvern had the same id, but they were different. Undigested whether it is related to the fact that strings are immutable.
@ yuba's Comment told me about the ID returned by ʻid () `.
Thank you for the information.
@ shiracamus's Comment told me about the dictionary to assign to (local dictionary, global dictionary).
Thank you for the information.
Recommended Posts