| 函数类型 | 语句 |
|---|---|
| 内置函数 | max([1,2,3]) import math math.floor(3.2) math.ceil(3.2) |
| 第三方模块函数 | import numpy as np import pandas as pd np.array([1,2,3]) pd.Series([1,2,3]) pd.Dataframe([1,2,3]) pd.Dataframe([[1,2,3]]) |
| 自定义函数 | def function(par1, par2, …): suite函数主体 return expression |
| 匿名函数 | a = [lambda x,i=i:x+i for i in range(10)] for i in a: print(i(1)) |
| 函数参数 | 语句 |
|---|---|
| 位置参数 | def func1(a,b,c): return (a**2, b**2, c**2) func1(1,2,3) |
| 关键字参数 | func1(b=1,a=2,c=3) |
| 默认参数 | def func2(a,b,c=2): return (a**2, b**2, c**2) func2(b=1,a=2) |
| 比较项 | 特点 |
|---|---|
| 函数 | 将一些语句集合在一起,使其能够反复在程序中运行。 |
| 函数目的 | 提高编程效率,避免大量写重复代码的工作。 |



