Research breakthrough possible @S-Logix

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • +91- 81240 01111

Social List

What is local and global variables in python?


To know about local & global variables in python3.

Local variables

  It should be declared within the function.

  We can use local variables within their scope only.

Global variables

   It should be declare outside the function.

  If it is declare within the function use global keyword at the start of the declaration.

  Once made change in global variable the entire program will be change.

   We can use global variable anywhere in the program.

Sample Code

#declare a global variable

y = 5

#declare a global variable

with in function

#declare a local variable a

def func1(a):

global z

z = 3

return a*z

#declare another function

with local variable x

def func2(x):

return x*y

#method call using

positional arguments

total = func1(3)

total1 = func2(4)


#print the result


(“multiplication of local and global variable is:”,total)



(“multiplication of local and global variable is:”,total1)

What is local and global variables in python