函数 函数参数

#函数
def test(x):
y = 2*x + 1
return y
x = 3
print(test(x))

#过程就是没有返回值的函数
#函数无返回值 返回None 返回一个值返回值本身 返回多个值 返回元祖
#默认参数
def handle(x,type='sql'):
print(x)
print(type)

handle('hello')
handle('hi',type='orcal')
#位置参数
handle('nihao','中文')

#参数组 **字典 *列表
def ceshi(x,*args):
print(x)
print(args)
print(args[0])

ceshi(1,2,3,4,8)
ceshi(1,[2,3,4])
ceshi(1,*[2,3,4])
ceshi(6,{'args':'lsdk'})


def ceshi1(x,**kwargs):
print(x)
print(kwargs)

ceshi1(1,**{'kwargs':'2222'})
ceshi1(1,y=2,z=3)

def ceshi2(x,*args,**kwargs):
print(x)
print(args)
print(kwargs)

#函数的优势:1、代码重用 2、保持一致性,易维护 3、可扩展性
原文地址:https://www.cnblogs.com/lqcjlu/p/12893125.html