-1

I'm making a program that uses a variable called "lev" that must be used in all my functions, but it doesn't need to be an argument of the function. I mean, the function makes some things and then changes "lev" value, so I need something like this:

>>> lev=8
>>> def t():
>>>      print 1+1
>>>      lev = lev+1
>>> t()
>>> lev
9

That was my first idea, but in practice, doing this, doesn't work.

I can't use "return" to get the new "lev" variable, because there are functions that I need to return a True or False from them AND edits the value of "lev" too, so I can't use the "return" command. Someone has an idea? Thanks

iam_agf
  • 639
  • 2
  • 9
  • 20

1 Answers1

1

Define it global lev in the function ...

>>> lev=8
>>> def t():
>>>      global lev
>>>      print 1+1
>>>      lev = lev+1
>>> t()
>>> lev
9
Srinath Mandava
  • 3,384
  • 2
  • 24
  • 37