Using Local Variable in a Function in Python

Source code :

# This is a global variable
Power = '100%'

def func():
# Local Variable
    Power = '200%'
    print('Power is', Power)
    
func()

Output :

Power is 200%

Notes :

  • The Variable Power have two diferent values in code, But the function can access only the local variable in it.

  • Global variable is ignored.

Output :


                

Comments :