The difference between local variables and global variables

I tried to use function to calculate some variables, but found that I can't distinguish between local or global variables

like this

function T1() 
{
    a1 = 1;
}

a1 = 0 
T1();

print a1; 

the a1 still 0

and then

a2 = 0; 

function T2() 
{
     a2 = 1;
}

T2();
print a2 ;

the a2 will be 1 ,

what's the difference

See Local & Global Variables Document.

Thank alot , the is what i want !!