1,093 views

1 Answer

0 0 votes

Global Variables: 
Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program. 

Local Variables: 
Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.

a=2 #Global Variable
def add():
    b=3   #Local Variable
    c=a+b #Local Variable
    print(c)
add()

When you try to access the local variable outside the function add(), it will throw an error.

Related questions

1 1 vote
1 1 answer
1.3k
1.3k views
0 0 votes
1 1 answer
886
886 views
2 2 votes
1 answers 1 answer
1.2k
1.2k views
askpython asked Jul 11, 2019
1,193 views
1 1 vote
1 1 answer
892
892 views
askpython asked Jul 11, 2019
892 views
1 1 vote
1 1 answer
5.6k
5.6k views