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 smtplibfrom email.mime.text import MIMETextfrom 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(函数-参数)的更多相关文章
- Python3 open()函数参数
open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=No ...
- Python3基础 函数 参数 多个参数都有缺省值,需要指定参数进行赋值
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Python3基础 函数 参数为list可变类型时,使用append会影响到外部实参
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Python3基础 函数 参数为list 使用+=会影响到外部的实参
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Python3基础 函数 参数 在设定缺省值的情况下指明参数类型
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
- Python第七天 函数 函数参数 函数里的变量 函数返回值 多类型传值 函数递归调用 匿名函数 内置函数
Python第七天 函数 函数参数 函数里的变量 函数返回值 多类型传值 函数递归调用 匿名函数 内置函数 目录 Pycharm使用技巧(转载) Python第一天 ...
- 函数和常用模块【day04】:函数参数及调用(二)
本节内容 1.为什么要有参数 2.返回值 3.有参数函数调用 一.为什么要有参数? 无参数实现 def CPU报警邮件() #发送邮件提醒 连接邮箱服务器 发送邮件 关闭连接 def 硬盘报警邮件() ...
- Python3 isinstance() 函数
Python3 isinstance() 函数 描述 isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type(). isinstance() 与 type() 区别: typ ...
- Python3 round() 函数
Python3 round() 函数 Python3 数字 描述 round() 方法返回浮点数x的四舍五入值. 语法 以下是 round() 方法的语法: round( x [, n] ) 参数 ...
- Python3 reversed 函数
Python3 reversed 函数 Python3 内置函数 描述 reversed 函数返回一个反转的迭代器. 语法 以下是 reversed 的语法: reversed(seq) 参数 se ...
随机推荐
- swift 创建tableView 并实现协议
import UIKit class ViewController2: UIViewController,UITableViewDelegate,UITableViewDataSource{ ...
- Eclipse集成PDT+XDebug调试PHP脚本 https://svn.jcxsoftware.com/node?page=5 [转]
win7+xampp-win32-1.8.2-2-VC9+eclipse-jee-indigo-SR2-win32-x86_64.zip http://pjdong1990.iteye.com/blo ...
- ArrayList 学习笔记
接口 ArrayList实现了List接口,因此可以当作一个List来使用. 此外,ArrayList还实现RandomAccess接口和Serializable,说明ArrayList支 ...
- XShell连接 Linux系统,显示中文乱码
摘要: Linux系统,中文显示乱码 XShell是一个强大的安全终端模拟软件,它支持SSH1, SSH2及 Microsoft Windows平台的Telnet NetSarang Xshell 4 ...
- 强制转https
原文:http://blog.csdn.net/wzy_1988/article/details/8549290 需求简介 基于nginx搭建了一个https访问的虚拟主机,监听的域名是test.co ...
- mysql 分区表详解
项目中要一张库表实现 list分区.并且支持多种数据库. oracle 很顺利,只是mysql 听说5.1版本就已经支持了, 可是试了很多个版本,都不行,后来查到原因是要5.5 以上版本 分区才支持 ...
- Oracle 执行计划(Explain Plan)
如果要分析某条SQL的性能问题,通常我们要先看SQL的执行计划,看看SQL的每一步执行是否存在问题. 如果一条SQL平时执行的好好的,却有一天突然性能很差,如果排除了系统资源和阻塞的原因,那么基本可以 ...
- Hashtable键值集合
//Hashtable键值集合 键必须是维一的 类似于索引 Hashtable ht = new Hashtable(); ht.Add(, "中国"); ht.Add(, ); ...
- c3p0写连接池 Demo
1.导包 2.配置文件:名称必须为:c3p0-config.xml,且必须放在src根目录下 <c3p0-config> <!-- 默认配置,有且仅可出现一次 ,如果没有指定则使用这 ...
- QT-Demo-Colck-01
QT += widgets QT += core HEADERS += \ mainwindow.h SOURCES += \ mainwindow.cpp \ main.cpp #ifndef MA ...