Pythonの名前空間(メモ)
Pythonの変数は、名前空間ごとに定義される。
・関数の中と外
・クラスの中と外
・モジュールの中と外
では、名前空間が異なるため、変数は別々に定義される。
hoge.py
x = 1
def function():
x = 2
print(x)
function() # =>2
print(x) # =>1
関数内では x=2 で
関数外では x=1 。
x は別々に定義されている。
クラス、モジュールに関しても同様。
Author And Source
この問題について(Pythonの名前空間(メモ)), 我々は、より多くの情報をここで見つけました https://qiita.com/matsumotoshintaro/items/422293433aadfc180d88著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .