how to convert local scope to global scope in python

Solutions on MaxInterview for how to convert local scope to global scope in python by the best coders in the world

showing results for - "how to convert local scope to global scope in python"
Julieta
06 Aug 2019
1#local scope
2enemy = 5
3def increase_enemy():
4    enemy = 10
5    return (f"enemy inside the function {enemy}")
6
7print(increase_enemy())
8print(f"Enemy out side the function {enemy}")
9
10#converting local scope to global scope
11enemy = 5
12def increase_enemy():
13    global enemy
14    enemy = 10
15    return (f"enemy inside the function {enemy}")
16
17print(increase_enemy())
18print(f"Enemy out side the function {enemy}")