Skip to main content

Python: Global and Local Variables

Global Variables:

Global variables are the one that is defined and declared outside a function and we need to use them inside a function. This means that a global variable can be accessed inside or outside of the function.

Example:

a = "Hello World!!"

def func_1():
    print(a)

func_1() 

Output: Hello World!!

Local Variables:

Local variables are declared inside the function's body or in the local scope is known as a local variable.

Example:

def func_1():
    a = "Hello!!"
    print(a)

func_1() 

Output: Hello!!

Tags
Submitted by devanshi.srivastava on July 2, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.