def modify_list(arg_list):
arg_list=arg_list.append(5)
print("Inside function:", arg_list)
i_list=[10,20,30,40,50]
print("Before function call:", i_list)
modify_list(i_list)
print("After function call:", i_list)
Answer:
Before function call: [10, 20, 30, 40, 50]
Inside function: None
After function call: [10, 20, 30, 40, 50, 5]
问题:为什么Inside函数返回None。但是i_list修改了吗?
def modify_list(arg_list):
arg_list=arg_list + [60, 70, 80]
print("Inside function:", arg_list)
i_list=[10,20,30,40,50]
print("Before function call:", i_list)
modify_list(i_list)
print("After function call:", i_list)
Answer:
Before function call: [10, 20, 30, 40, 50]
Inside function: [10, 20, 30, 40, 50, 60, 70, 80]
After function call: [10, 20, 30, 40, 50]
问题:在这种情况下,为什么i_list没有像在第一种情况下那样被修改?