概念:
下面是蛮经典的解释:
What Good are Functions?
You might have considered the situation where you would like to reuse a piece of code, just with a few different values. Instead of rewriting the whole code, it's much cleaner to define a function, which can then be used repeatedly.
一。函数格式:
通常会有个return,返回调用函数后的结果值,return是可选的,如果函数没有用return,
函数执行完后,会返还一个none的对象。
另外,会有 yield语句。
二。定义:
eg1:
eg2:
高效的列表解析式:
三。调用:
四。python中的多态:
一个操作的意义,取决于操作中的数据类型,这种依赖类型的行为叫多态,使python成为了动态语言。