pythonrumen/ target=_blank class=infotextkey>python入门之函数,供初学python的朋友参考。
 
//函数的定义和调用
def sayHello():
  print 'hello,python!';
sayHello();
//局部变量、全局变量
#全局变量
a = 10
def fun1():
  #局部变量
  a = 3
  #全局变量
  global b
b = 100
pirnt b
print a
#默认参数
def sendEmail(context,toUser = 'test@jb200.com'):
    print 'send to '+toUser +" "  +context
#关键参数
sendEmail(context='nihao',toUser='790896688@qq.com')
#docStrings的写法和读发
def sendEmail(context = '',toUser = 'test@jb200.com'):
    '''context is the context to send ,
        toUser is the adrress of email to send'''
    print 'send '+context+' to '+toUser
sendEmail.__doc__