'''
Created on 2011-9-29
@author: xgzhao
'''
# variant parameters in function definition
def fun(name, age=12, *rest):
print name, age
print [i for i in rest]
# use dictionary as key parameters
def function(name, age=13, *rest, **dictionary):
for d in dictionary.keys():
print d
#anonymity function: lambda
true = lambda : True
print true()
#provide the same function
def add(x, y): return x+y
lambda x, y : x+y
print map((lambda x:x+2), [0, 1, 2, 3, 4, 5, 6])
python中函数的几个小知识点
本文介绍了Python中函数定义的各种高级技巧,包括使用默认参数、不定长参数、字典参数、匿名函数等,并展示了如何利用这些特性来简化代码。

被折叠的 条评论
为什么被折叠?



