<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>yohhoy</author_name>
  <author_url>https://blog.hatena.ne.jp/yohhoy/</author_url>
  <blog_title>yohhoyの日記</blog_title>
  <blog_url>https://yohhoy.hatenadiary.jp/</blog_url>
  <categories>
    <anon>Python</anon>
  </categories>
  <description>プログラミング言語Pythonにおいて、関数やラムダ式にローカル変数の「値」を束縛する方法。下記コードでは “引数xを定義時の値nで冪乗” する関数を個別生成するつもりが、実際には “引数xを変数nの値で冪乗” する同一の関数が生成される。forループ終了後の変数nは値3となっており、プログラマの期待に反する実行結果となる。 # 関数 ops = [] for n in range(4): def fn(x): return x ** n ops.append(fn) print([f(2) for f in ops]) # [8, 8, 8, 8] # ラムダ式 ops = [] for n…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fyohhoy.hatenadiary.jp%2Fentry%2F20201118%2Fp1&quot; title=&quot;関数／ラムダ式への値束縛 - yohhoyの日記&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>2020-11-18 00:00:00</published>
  <title>関数／ラムダ式への値束縛</title>
  <type>rich</type>
  <url>https://yohhoy.hatenadiary.jp/entry/20201118/p1</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
