Can we make a local variable in a function as global variable???

7stud bbxx789_05ss at
Thu Apr 5 11:40:13 CEST 2007

On Apr 5, 3:19 am, "sairam" <sai... at> wrote:
> I have some local variables defined in one method and Can I make those
> variables as global variables? If so , can any one explain me how can
> I do that
> Thanks,
> Sairam
num = None

def f1():
    global num
    num = 30

def f2():
    print num

You can read from a global variable, but to assign to one, you have to
declare its name in a global statement on the first line of the

A better way:
def f1():
    num = 30
    return num

def f2(x):
    print x

result = f1()

More information about the Python-list mailing list