1.school = 'oldboy.edu'

def change_name(name):

 

      school = " Mage Linux"                  # 局部变量只在函数里生效

       print(name, school)

 

name = 'Alex' 

change_name(name)  #先调用

print(school)

2.

school = 'oldboy.edu' 

def change_name(name):

        global school           #设置全局变量

        school = " Mage Linux"  

        print(name, school)

name = 'alex'

change_name(name)

print(school)

3.

school = 'oldboy edu.'
names = ['Alex', 'Jack', 'Rain']

def change_name():         # 字符串和整数不能修改, 字典和列表可以在局部变量中被修改

      names[0] = 'alex'

       print('inside func', name)

change_name()

print(name)

 

 

 

       

posted on 2018-05-14 16:50  python我的最爱  阅读(143)  评论(0编辑  收藏  举报