Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
重複の可能性: Python メソッドに「self」引数を明示的に指定する必要があるのはなぜですか?
Python では、インスタンス変数は 経由self.xでアクセスする必要がありますが、グローバル変数は と書くだけで読み取ることができますx。どうして?
self.x
x
これはよくある質問ですが、基本的には、名前の競合や、インスタンスまたはグローバル変数のどちらがアクセスされているかについての混乱を避けるためです。
哲学は「明示的は暗黙的よりも優れている」です。