python 中的参数传递

# 小郑之家~

### 数字

num = 1
def test1(num):
num += 10
test1(num)
print(num)



1


### 字符串

s = "zw"
def test2(s):
s += "k"
test2(s)
print(s)



zw



### 列表

lst = [2,3]
def test3(lst):
lst.append(4)

test3(lst)
print(lst)



[2,3,4]



lst = [2,3]
lst2 = lst
lst3 = []
lst3[:] = lst
def test3(lst,lst2,lst3):
lst.append(4)
lst2.append(4)
lst3.append(4)

test3(lst, lst2, lst3)
print(lst,lst2,lst3)



[2, 3, 4, 4] [2, 3, 4, 4] [2, 3, 4]



lst = [2,3]
#lst2 = lst
lst3 = []
lst3[:] = lst
def test3(lst3):
#lst.append(4)
#lst2.append(4)
lst3.append(4)

test3(lst3)
print(lst,lst3)



[2, 3] [2, 3, 4]



import copy
lst4 = copy.deepcopy(lst)
test3(lst4)
print(lst, lst4)

lst5 = copy.deepcopy(lst)
test3(lst5)
print(lst, lst5)



[2, 3] [2, 3, 4]
[2, 3] [2, 3, 4]
[2, 3] [2, 3, 4]



### 字典

dic = {"a":1}
def test4(dic):
dic["a"] = 2
dic["b"] = 3

test4(dic)
print(dic)



{'a': 2, 'b': 3}



### numpy

import numpy as np
ar1 = np.array([3,4])
def test5(ar1):
ar1[0] = 10
ar1[1] = 13

test5(ar1)
print(ar1)
~



[10 13]



`