Home >>Python Keywords >Python global Keyword

Python global Keyword

Python global Keyword

Python global keyword is used to create a global variables from a non-global scope i.e inside a function that allows a user to modify a variable outside of the current scope.

Here is an example of Python global Keyword:

def myglobe():
global z
z = "Welcome to phptpoint"
myglobe()
print(z)

Output:
Welcome to phptpoint
Example 2:

x = 35
y = 20
def add(): 
	z = x + y 
	print(z)  
add()

Output:
55

No Sidebar ads