7872人加入学习
(35人评价)
Python零基础入门学习2020最新版(SiKi)

使用Python3.8 于2019/10/20开始录制

价格 免费

函数和字典结合使用:

def test(n,a):
    d = {'name': n, 'age': a}
    return d

print(test('siki','18'))

 

函数和列表结合使用:

如果给函数传递了列表,则函数里的会对原列表进行修改,例如:

l = [ 'siki' , 'libai' , 'dufu' ]
def test(l):
    del(l[1])

test(l)
print(l)

则l里的‘libai’会删掉

 

如何不使原函数发生变化?复制一份,例如:

l = [ 'siki' , 'libai' , 'dufu' ]
def test(l):
    del(l[1])

test(l[:])
print(l)

 

[展开全文]