<div dir="ltr"><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 13, 2020 at 4:02 PM Gabriele Battaglia <<a href="mailto:iz4apu@libero.it">iz4apu@libero.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">[...]<br></blockquote><div><br></div><div>Ciao,</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Qual è l'inghippo?<br>
<br></blockquote><div><br></div><div>Lo scope delle variabili.</div></div><div class="gmail_quote"><br></div><div class="gmail_quote"><span style="font-family:monospace">>>> a = 10<br>>>> def do():<br>... a = a + 1<br>... print(a)<br>...<br>>>> print(a)<br>10<br>>>> do()<br>Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br> File "<stdin>", line 2, in do<br>UnboundLocalError: local variable 'a' referenced before assignment<br>>>> def do():<br>... a = 15<br>... return a<br>...<br>>>> print(a)<br>10<br>>>> print(do())<br>15<br>>>> print(a)<br>10</span></div><div class="gmail_quote"><br></div><div class="gmail_quote">Qui un bell'articolo che ti spiega tutto bene bene: <a href="https://realpython.com/python-scope-legb-rule/">https://realpython.com/python-scope-legb-rule/</a></div><div class="gmail_quote"><br></div><div class="gmail_quote">Sani</div><div class="gmail_quote">Strap</div><div class="gmail_quote"><br></div></div>