python 中函数的理解 一

#定义第一个函数
def hello():
    print "hello world!"

res=hello()
res

>>>hello  world!

#关键字函数

#因为python是动态语言所以函数的参数获得的值往往会安置倒位 甚至有时候还有默认函数
def foo(x,y):
    print x,y
print foo(y='56',x=49)

>>>49  56
#如上所示即使参数的传递顺序不也木有关系

 

#默认参数
def foo(host='localhost',port='8080'):
    print '%s:%s'%(host,port)

print foo()
>>> localhost:8080

 

posted on 2015-05-14 16:11  象牙塔里的魔术师  阅读(161)  评论(0)    收藏  举报

导航