标签:
1.参数
函数的核心是参数传值,其次是返回值,熟练这两这个技术即可灵活使用函数。
1>普通参数
def show(name):
print(name)
show(‘tom‘)
2>默认参数
def show(name,age=18)
print("%s,%s"%(name,age))
show(‘tom‘,19)
show(‘tom‘)
3>动态参数-序列
def show(*args):
print(args)
show(11,22,33)
li=[11,22,33,44]
show(*li)
4>动态参数-字典
def show(**kwargs):
print(args)
show(name=‘tom‘,age=18)
d={name=‘tom‘,age=18,sex=male}
show(**d)
5>动态参数-序列字典
def show(*args,**kwargs):
print(args)
print(kwargs)
6>扩展:邮件发送实列
import smtplib from email.mime.text import MIMEText from email.utils import formataddr msg = MIMEText( ‘邮件内容‘ , ‘plain‘ , ‘utf-8‘ ) msg[ ‘From‘ ] = formataddr([ "武沛齐" , ‘wptawy@126.com‘ ]) msg[ ‘To‘ ] = formataddr([ "走人" , ‘424662508@qq.com‘ ]) msg[ ‘Subject‘ ] = "主题" server = smtplib.SMTP( "smtp.126.com" , 25 ) server.login( "wptawy@126.com" , "邮箱密码" ) server.sendmail( ‘wptawy@126.com‘ , [ ‘424662508@qq.com‘ ,], msg.as_string()) server.quit()
|
标签:
原文地址:http://www.cnblogs.com/weibiao/p/5187349.html