Answers for "how to convert local scope to global scope in python"

1

how to convert local scope to global scope in python

#local scope
enemy = 5
def increase_enemy():
    enemy = 10
    return (f"enemy inside the function {enemy}")

print(increase_enemy())
print(f"Enemy out side the function {enemy}")

#converting local scope to global scope
enemy = 5
def increase_enemy():
    global enemy
    enemy = 10
    return (f"enemy inside the function {enemy}")

print(increase_enemy())
print(f"Enemy out side the function {enemy}")
Posted by: Guest on August-30-2021

Python Answers by Framework

Browse Popular Code Answers by Language