Python课程第八天_下午_课程笔记(值传递和引用传递Value_Passing_And_Reference_Passing)

Day_08_PM_Value_Passing_And_Reference_Passing

# 基本类型: 不可变类型
#   int, float, str, tuple, bool, None
# 引用类型: 可变类型
#   list, dict, set

# 基本类型赋值: 不关联
a = 10
b = a
a = 20
print(a, b)  # 20 10

# 引用类型赋值: 关联
l1 = [1, 2, 3]
l2 = l1
l1[0] = 99
print(l1, l2)  # [99, 2, 3] [99, 2, 3]

# 函数中
age = 10
person = {'name':'小明', 'age':43}

def change_age(age1, person1):
    global age
    age1 += 1
    person1['age'] += 1

change_age(age, person)

print(age, person)

猜你喜欢

转载自blog.csdn.net/weixin_44298535/article/details/107672931