函数

# def test(x,y,z):#x=1,y=2,z=3
# print(x)
# print(y)
# print(z)

#位置参数,必须一一对应,缺一不行多一也不行
# test(1,2,3)

#关键字参数,无须一一对应,缺一不行多一也不行
# test(y=1,x=3,z=4)

#位置参数必须在关键字参数左边
# test(1,y=2,3)#报错
# test(1,3,y=2)#报错
# test(1,3,z=2)
# test(1,3,z=2,y=4)#报错
# test(z=2,1,3)#报错

# def handle(x,type='mysql'):
# print(x)
# print(type)
# handle('hello')
# handle('hello',type='sqlite')
# handle('hello','sqlite')

# def install(func1=False,func2=True,func3=True):
# pass

#参数组:**字典 *列表
def test(x,*args):
print(x)
print(args)

args(列表可以为空,即如果以后可能会传多个参数的话,可以预留这个使用)


# test(1)
# test(1,2,3,4,5)
# test(1,{'name':'alex'})
# test(1,['x','y','z'])
# test(1,*['x','y','z'])
# test(1,*('x','y','z'))

# def test(x,**kwargs):
# print(x)
# print(kwargs)
# test(1,y=2,z=3)
# test(1,1,2,2,2,2,2,y=2,z=3)#会报错 :位置参数必须一一对应,不能多
# test(1,y=2,z=3,z=3)#会报错 :一个参数不能传两个值

def test(x,*args,**kwargs):
print(x)
print(args,args[-1])
print(kwargs,kwargs.get('y'))
# test(1,1,2,1,1,11,1,x=1,y=2,z=3) #报错
# test(1,1,2,1,1,11,1,y=2,z=3)

# test(1,*[1,2,3],**{'y':1})

 

运行函数 就是运行函数对应的内存地址

 

没有返回值的函数 相当于返回一个none

posted @ 2020-07-06 14:08  好好学习_liu  阅读(124)  评论(0编辑  收藏  举报