python 中函数的理解 一

时间:2015-05-14 17:59:29   收藏:0   阅读:169

#定义第一个函数
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

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!