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)

python3-day3(函数-参数)的更多相关文章

  1. Python3 open()函数参数

    open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=No ...

  2. Python3基础 函数 参数 多个参数都有缺省值,需要指定参数进行赋值

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  3. Python3基础 函数 参数为list可变类型时,使用append会影响到外部实参

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  4. Python3基础 函数 参数为list 使用+=会影响到外部的实参

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  5. Python3基础 函数 参数 在设定缺省值的情况下指明参数类型

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  6. Python第七天 函数 函数参数 函数里的变量 函数返回值 多类型传值 函数递归调用 匿名函数 内置函数

    Python第七天   函数  函数参数   函数里的变量   函数返回值  多类型传值     函数递归调用   匿名函数   内置函数 目录 Pycharm使用技巧(转载) Python第一天   ...

  7. 函数和常用模块【day04】:函数参数及调用(二)

    本节内容 1.为什么要有参数 2.返回值 3.有参数函数调用 一.为什么要有参数? 无参数实现 def CPU报警邮件() #发送邮件提醒 连接邮箱服务器 发送邮件 关闭连接 def 硬盘报警邮件() ...

  8. Python3 isinstance() 函数

    Python3 isinstance() 函数 描述 isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type(). isinstance() 与 type() 区别: typ ...

  9. Python3 round() 函数

    Python3 round() 函数  Python3 数字 描述 round() 方法返回浮点数x的四舍五入值. 语法 以下是 round() 方法的语法: round( x [, n] ) 参数 ...

  10. Python3 reversed 函数

    Python3 reversed 函数  Python3 内置函数 描述 reversed 函数返回一个反转的迭代器. 语法 以下是 reversed 的语法: reversed(seq) 参数 se ...

随机推荐

  1. 魅蓝Note2跑分 MT6753性能究竟如何

    MT6753实力究竟如何? 采用LP工艺的MT6753实际上在性能和功耗方面并不比MT6752高,相反,同频下功耗要高1/3左右.并且其内存带宽是5.3G/s,小于MT 6752的6.4G/s 而且没 ...

  2. Linux安装mysql源码

    1.假设已经有mysql-5.5.10.tar.gz以及cmake-2.8.4.tar.gz两个源文件 (1)先安装cmake(mysql5.5以后是通过cmake来编译的) [root@ rhel5 ...

  3. 五、SolrJ、Request Handler

    什么是SolrJ 既然Solr是以单独的WebApp形式存在的,那么Solr理应提供与Solr通信的Api吧,对的,这就是SolrJ,既然与solr通信是通过url,那么其实我们也可以不用SolrJ, ...

  4. OD: Exploit Me - Overwrite Nearby Varible

    实验代码: #include<stdio.h> #include<string.h> #define PASSWORD "1234567" int veri ...

  5. javascript 冒泡和事件源 形成的事件委托

    冒泡:即使通过子级元素的事件来触发父级的事件,通过阻止冒泡可以防止冒泡发生. 事件源:首先这个东西是有兼容行问题的,当然解决也很简单. 两者结合使用,形成的事件委托有两个优势: 1.减少性能消耗: 2 ...

  6. foreach遍历扩展(二)

    一.前言 假设存在一个数组,其遍历模式是根据索引进行遍历的:又假设存在一个HashTable,其遍历模式是根据键值进行遍历的:无论哪种集合,如果它们的遍历没有一个共同的接口,那么在客户端进行调用的时候 ...

  7. 【回忆1314】回忆之placeholder

    直接看效果点这里 HTML <!DOCTYPE html> <html> <head lang="zh-CN"> <meta charse ...

  8. HTML&CSS基础学习笔记1.24-input标签的单选与多选

    单选和多选 单选框和多选框是用<input>标签来实现的. <input>标签的type属性值为"checkbox"时,表示多选框,为"radio ...

  9. arm get_vector_swi_address

    unsigned long* get_vector_swi_addr() { const void *swi_addr = 0xFFFF0008; unsigned ; unsigned ; unsi ...

  10. 《转》JAVA动态代理(JDK和CGLIB)

    该文章转自:http://www.cnblogs.com/jqyp/archive/2010/08/20/1805041.html JAVA的动态代理 代理模式 代理模式是常用的java设计模式,他的 ...