0

For example:

def test(a)
   a = 2
   b = 5+a
   x = a*2
   return x

Is there a way to call the variable 'b' outside of the function?

user10939484
  • 167
  • 2
  • 13

1 Answers1

1
b = None

    def test(a)
       global b
       a = 2
       b = 5+a
       x = a*2
       return x

print(b)

Although we will suggest to return b and then access it, as global variable is a bad idea. See this, Why are global variables evil?

Ankit Agrawal
  • 596
  • 5
  • 12