## 函数

'''函数调用'''
def printme(str):
print(str)

printme("我要调用用户自定义函数!")  # 我要调用用户自定义函数!
printme("再次调用同一函数")  # 再次调用同一函数
temp = printme('hello') # hello
print(temp)  # None

'''函数文档'''
def MyFirstFunction(name):
"函数定义过程中name是形参"
# 因为Ta只是一个形式，表示占据一个参数位置
print('传递进来的{0}叫做实参，因为Ta是具体的参数值！'.format(name))

MyFirstFunction('我爱Python')
# 传递进来的我爱Python叫做实参，因为Ta是具体的参数值！

print(MyFirstFunction.__doc__)
# 函数定义过程中name是形参

help(MyFirstFunction)
# Help on function MyFirstFunction in module __main__:
# MyFirstFunction(name)
#    函数定义过程中name是形参

'''可变参数'''
def printinfo(arg1, *args):
print(arg1)
for var in args:
print(var)

printinfo(10)  # 10
printinfo(70, 60, 50)

# 70
# 60
# 50

'''关键字参数'''
def printinfo(arg1, *args, **kwargs):
print(arg1)
print(args)
print(kwargs)

printinfo(70, 60, 50)
# 70
# (60, 50)
# {}
printinfo(70, 60, 50, a=1, b=2)
# 70
# (60, 50)
# {'a': 1, 'b': 2}

## Lambda表达式

'''匿名函数'''
def sqr(x):
return x ** 2

print(sqr)
# <function sqr at 0x000000BABD3A4400>

y = [sqr(x) for x in range(10)]
print(y)
# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

lbd_sqr = lambda x: x ** 2
print(lbd_sqr)
# <function <lambda> at 0x000000BABB6AC1E0>

y = [lbd_sqr(x) for x in range(10)]
print(y)
# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

sumary = lambda arg1, arg2: arg1 + arg2
print(sumary(10, 20))  # 30

func = lambda *args: sum(args)
print(func(1, 2, 3, 4, 5))  # 15

'''函数式编程'''
def f(x):
y = []
for item in x:
y.append(item + 10)
return y

x = [1, 2, 3]
f(x)
print(x)
# [1, 2, 3]