<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>tmg1998</author_name>
  <author_url>https://blog.hatena.ne.jp/tmg1998/</author_url>
  <blog_title>TIL</blog_title>
  <blog_url>https://tmg0525.hatenadiary.jp/</blog_url>
  <categories>
    <anon>python</anon>
  </categories>
  <description>ネストした関数で、上で定義された変数を使うにはnonlocalキーワードを使う def main(): a = 1 def child(): nonlocal a a += 1 print(a) print(a) child() print(a) main() 出力結果 1 2 2 ネストした関数から、アクセスできた！！ これは、メモ化のための実装方法らしい。クロージャというやつ メモ化ってどっかで聞いたことある。 たしか、同じ引数だったら、前回の結果をそのまま返すやつだっけ クロージャについてはこんどちゃんとやる。こんど。うん。 参考文献 Python超入門その１４〜意外と重要なスコープを理…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Ftmg0525.hatenadiary.jp%2Fentry%2F2018%2F11%2F08%2F012636&quot; title=&quot;nonlocal ネストした関数から変数にアクセスする - Python - TIL&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2018-11-08 01:26:36</published>
  <title>nonlocal ネストした関数から変数にアクセスする - Python</title>
  <type>rich</type>
  <url>https://tmg0525.hatenadiary.jp/entry/2018/11/08/012636</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
