Python program to print the string using global declaration method

A Python program to print the string using global declaration method. In this program we can print the string which is declared in global. In Python, a global variable is a variable that is defined outside of the function or in the global scope. Both inside and outside of the code, a global variable can be accessed. Let’s have a look at how to create a global variable in Python with an example.

The global keyword is used to change a global variable’s scope and meaning. It’s used to make changes to a global variable in a local context. The keyword ‘Global’ is also used to construct or define a global variable within a function.

def myfunc():
global x
x = "awesome in inlarn.com"
myfunc()
print("Python is " + x)

 

Output:

Python is awesome in inlarn.com