[dywang@deyu zzz]$ cat function7.py
#!/usr/bin/python3
# coding: utf-8
total = 0; # This is global variable.
# Function definition is here
def sum( arg1, arg2 ):
# Add both the parameters and return them."
total = arg1 + arg2; # Here total is local variable.
print("Inside the function local total :", total)
return total;
# Now you can call sum function
sum( 10, 20 );
print("Outside the function global total :", total)
[dywang@deyu zzz]$ ./function7.py Inside the function local total : 30 Outside the function global total : 0
[dywang@deyu zzz]$ cat function7a.py
#!/usr/bin/python3
# coding: utf-8
total = 0; # This is global variable.
# Function definition is here
def sum( arg1, arg2 ):
# Add both the parameters and return them."
total = arg1 + arg2; # Here total is local variable.
print("Inside the function local total :", total)
return total;
# Now you can call sum function
total = sum( 10, 20 );
print("Outside the function global total :", total)
[dywang@deyu zzz]$ ./function7a.py Inside the function local total : 30 Outside the function global total : 30