<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>nainaistar</author_name>
  <author_url>https://blog.hatena.ne.jp/nainaistar/</author_url>
  <blog_title>きり丸の技術日記</blog_title>
  <blog_url>https://nainaistar.hatenablog.com/</blog_url>
  <categories>
    <anon>Python</anon>
    <anon>技術</anon>
  </categories>
  <description>有名な話ですがハマったのでブログにします。 環境 Python 3.9 事象 Pythonでデフォルト引数に配列を定義すると、意図せずに同じインスタンスを使用してしまう。 def target_1(value, list=[]): list.append(value) return list def test_01(): a = target_1(&quot;1&quot;) # [&quot;1&quot;] assert len(a) == 1 b = target_1(&quot;2&quot;) # a, b 両方とも次の値になる # [&quot;1&quot;, &quot;2&quot;] assert len(a) == 2 assert len(b) == 2 # インスタ…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fnainaistar.hatenablog.com%2Fentry%2Fshould-not-use-mutable-in-python%2527s-default-parameter&quot; title=&quot;Pythonのデフォルト引数では配列ではなくNoneを使わないとダメ（ミュータブルはNG） - きり丸の技術日記&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>https://cdn-ak.f.st-hatena.com/images/fotolife/n/nainaistar/20231112/20231112142841.png</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2023-11-13 12:00:00</published>
  <title>Pythonのデフォルト引数では配列ではなくNoneを使わないとダメ（ミュータブルはNG）</title>
  <type>rich</type>
  <url>https://nainaistar.hatenablog.com/entry/should-not-use-mutable-in-python%27s-default-parameter</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
