aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/posts/2021-10-02/python-unbound-local-error
diff options
context:
space:
mode:
Diffstat (limited to 'public/posts/2021-10-02/python-unbound-local-error')
-rw-r--r--public/posts/2021-10-02/python-unbound-local-error/index.html6
1 files changed, 3 insertions, 3 deletions
diff --git a/public/posts/2021-10-02/python-unbound-local-error/index.html b/public/posts/2021-10-02/python-unbound-local-error/index.html
index fa0b1db..27c2d05 100644
--- a/public/posts/2021-10-02/python-unbound-local-error/index.html
+++ b/public/posts/2021-10-02/python-unbound-local-error/index.html
@@ -60,7 +60,7 @@
Python でクロージャを作ろうと、次のようなコードを書いた。
</p>
- <pre language="python" linenumbering="unnumbered">
+ <pre class="highlight" language="python" linenumbering="unnumbered">
<code>def f():
x = 0
def g():
@@ -84,7 +84,7 @@ f()</code>
local変数<code>x</code>が代入前に参照された、とある。これは、<code>f</code>の<code>x</code>を参照するのではなく、新しく別の変数を<code>g</code>内に作ってしまっているため。 前述のコードを宣言と代入を便宜上分けて書き直すと次のようになる。<code>var</code>を変数宣言のための構文として擬似的に利用している。
</p>
- <pre language="python" linenumbering="unnumbered">
+ <pre class="highlight" language="python" linenumbering="unnumbered">
<code># 注: var は正しい Python の文法ではない。上記参照のこと
def f():
var x # f の local変数 &apos;x&apos; を宣言
@@ -101,7 +101,7 @@ g()</code>
当初の意図を表現するには、次のように書けばよい。
</p>
- <pre language="python" linenumbering="unnumbered">
+ <pre class="highlight" language="python" linenumbering="unnumbered">
<code>def f():
x = 0
def g():