package cn.xh.test;
public class Fun_test {
static int glob=10;
public static void main(String[] args) {
// TODO Auto-generated method stub
Fun_test fun=new Fun_test();
fun.change();
System.out.println(">>>"+glob);
}
public void change()
{
glob=5;
System.out.println(glob);
}
}
public class Fun_test {
static int glob=10;
public static void main(String[] args) {
// TODO Auto-generated method stub
Fun_test fun=new Fun_test();
fun.change();
System.out.println(">>>"+glob);
}
public void change()
{
glob=5;
System.out.println(glob);
}
}
结果:
5
>>>5
**************************************************************************
glob=10
def change():
glob=5
print(glob)
change()
print(">>>"+str(glob))
结果:
5
>>>10
**************************************************************************
glob=10
def change():
global glob
glob=5
print(glob)
change()
print(">>>"+str(glob))
结果:
5
>>>5