代码实验展示:形式参数中的基本数据类型的修改不会影响实际参数;但是形式参数中的列表数据类型的修改会影响到实际参数中的列表,因为它们实际操作的是同一个数据,即同一个列表.
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> def fun(i):
i += 1
print('i =',i)
>>> fun(20200910)
i = 20200911
>>>
>>> n = 20200910
>>> fun(n)
i = 20200911
>>> n
20200910
>>>
>>> i = 20200910
>>> fun(i)
i = 20200911
>>>
>>> i
20200910
>>>
>>>
>>>
>>> def funList(ls):
ls[-1] = 'SCM insulted me in 20200910'
print('列表的内容是:',ls)
>>> ls = [0,1,2,3]
>>> ls
[0, 1, 2, 3]
>>> print(ls)
[0, 1, 2, 3]
>>>
>>> funList(ls)
列表的内容是: [0, 1, 2, 'SCM insulted me in 20200910']
>>>
>>> ls
[0, 1, 2, 'SCM insulted me in 20200910']
>>>
>>> LS = ['A','B','C','D']
>>> ls
[0, 1, 2, 'SCM insulted me in 20200910']
>>> LS
['A', 'B', 'C', 'D']
>>> funList(LS)
列表的内容是: ['A', 'B', 'C', 'SCM insulted me in 20200910']
>>>
>>> LS
['A', 'B', 'C', 'SCM insulted me in 20200910']
>>>
>>>
>>>