zoukankan      html  css  js  c++  java
  • python3-day3(函数-参数)

    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>example

        #example *
        s1 ="{0} is {1}"
        l=['alex','teacher']
        #result=s1.format('alex','teacher')
        result=s1.format(*l)
        print(result)
        #example **
        s1 = "{name} is {acter}"
        d = {'name':'alex','acter':'teacher'}
        #result= s1.format(name='alex',acter='teacher')
        result=s1.format(**d)
        print(result)

        7>扩展:邮件发送实列

    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()

     

       8>lambda(函数的简单表达方式)

        def func(a):

            a +=1

         return a

         result=func(4)

        print(result)


        f= lambda a: a+1
        ret = f(99)
        print(ret)
  • 相关阅读:
    showSoftInput不起作用
    GridView在PopWindow中OnItemClick不响应
    白盒测试范围
    Winform的ListBox的ValueMember和DisplayMember绑定的名称所属对象必须是Public的。
    谷歌浏览器安装adblock广告屏蔽插件
    php+curl上传文件
    win10我能ping通他人,但他人ping不同我
    自己的配置文件以及操作
    安装redis,执行make test时遇到You need tcl 8.5 or newer in order to run the Redis test
    安装redis时遇到zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
  • 原文地址:https://www.cnblogs.com/weibiao/p/5187349.html
Copyright © 2011-2022 走看看