Re: Variable scope inside and outside functions

Liste des GroupesRevenir à cl python 
Sujet : Re: Variable scope inside and outside functions
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 05. Mar 2024, 19:46:31
Autres entêtes
Organisation : Stefan Ram
Message-ID : <global-20240305194545@ram.dialup.fu-berlin.de>
References : 1
Jacob Kruger <jacob.kruger.work@gmail.com> wrote or quoted:
l_servers = []
...
    global l_servers
That should, in theory, mean that if I assign a value to that variable
inside one of the functions, it should reflect globally?

  Yes.

l =[ 1, 2, 3 ]

def f():
    global l
    l =[ 2, 3, 4 ]

f()

print( l )
# [2, 3, 4]

Date Sujet#  Auteur
5 Mar 24 o Re: Variable scope inside and outside functions1Stefan Ram

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal