[Python] Un concetto difficile per me.
    Strap Lab 
    lab a strap.it
       
    Lun 16 Nov 2020 09:44:02 CET
    
    
  
On Fri, Nov 13, 2020 at 4:02 PM Gabriele Battaglia <iz4apu a libero.it> wrote:
> [...]
>
Ciao,
Qual è l'inghippo?
>
>
Lo scope delle variabili.
>>> a = 10
>>> def do():
...     a = a + 1
...     print(a)
...
>>> print(a)
10
>>> do()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in do
UnboundLocalError: local variable 'a' referenced before assignment
>>> def do():
...     a = 15
...     return a
...
>>> print(a)
10
>>> print(do())
15
>>> print(a)
10
Qui un bell'articolo che ti spiega tutto bene bene:
https://realpython.com/python-scope-legb-rule/
Sani
Strap
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20201116/6dc314a5/attachment.html>
    
    
       
       Maggiori informazioni sulla lista 
	       Python