Global Statement in Python.

Globa Statement:

Global variables are used for the Global scope which is define outside the function of a program. If we wnat to change the global variable value inside the local function then global keword is used to update the new value.

Without Global:

a=30 def demo(): a=20 print(a) demo() print(a)

output:

20 30

With Global:

a=30 def demo(): global a a=20 print(a) demo() print(a)

output:

20 20

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.