Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

What is local and global variables in python?

Description

To know about local & global variables in python3.

Process
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(“\n”)

#print the result

print

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

print(“\n”)

print

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

Screenshots
What is local and global variables in python