当前位置:网站首页>函数的默认参数&函数参数的多种方法
函数的默认参数&函数参数的多种方法
2022-07-05 12:40:00 【南湖渔歌】
# 函数的关键词参数:
def introduce(name, gender):
""" 幼儿园自我介绍 """
print(f"大家好,我的名字是:{
name},是个小{
gender}")
# 需要按顺序提供参数,顺序不能乱
introduce("小明", "男生")
introduce("小白", "女生")
# 可以用形参名 = 值 的方式提供实参
introduce(name = "小明", gender="男生")
introduce( gender="男生",name = "小明")
# 也可以 位置参数 和关键词参数 配合
introduce( "男生", gender= "小明")
# 函数的默认参数:
def introduce(name, gender,age = 6):
""" 幼儿园自我介绍 """
print(f"大家好,我的名字是:{
name},是个小{
gender},今年{
age}岁了")
#-------------------- 函数多种形式的参数 ------------------------
# 调用函数时,默认参数可以不写值
# 如何不设置age,那么就是6岁
introduce("小明", "男生")
# 如果传递一个新值,覆盖默认值
introduce("小明", "男生",age=5)
introduce("小明", "男生",5)
# 位置实参需要按顺序、关键字参数用 key=value可以换顺序、默认参数可以不填
introduce(age=8,name="小明", gender="男生")
边栏推荐
- Shi Zhenzhen's 2021 summary and 2022 outlook | colorful eggs at the end of the article
- CVPR 2022 | 基于稀疏 Transformer 的单步三维目标识别器
- Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
- 你的下一台电脑何必是电脑,探索不一样的远程操作
- 太方便了,钉钉上就可完成代码发布审批啦!
- Storage Basics
- Kotlin流程控制、循环
- Rasa Chat Robot Tutorial (translation) (1)
- 自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
- SAP UI5 视图里的 OverflowToolbar 控件
猜你喜欢
使用 jMeter 对 SAP Spartacus 进行并发性能测试
RHCAS6
【云原生】Nacos-TaskManager 任务管理的使用
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces
Vonedao solves the problem of organizational development effectiveness
Shi Zhenzhen's 2021 summary and 2022 outlook | colorful eggs at the end of the article
Four common problems of e-commerce sellers' refund and cash return, with solutions
Distance measuring sensor chip 4530a used in home intelligent lighting
Kotlin变量
How to connect the API interface of Taobao open platform (super detailed)
随机推荐
Four common problems of e-commerce sellers' refund and cash return, with solutions
Yyds dry inventory JS intercept file suffix
实战模拟│JWT 登录认证
Using MySQL in docker
How to connect the API interface of Taobao open platform (super detailed)
激动人心!2022开放原子全球开源峰会报名火热开启!
Laravel文档阅读笔记-mews/captcha的使用(验证码功能)
非技术部门,如何参与 DevOps?
滴滴开源DELTA:AI开发者可轻松训练自然语言模型
A possible investment strategy and a possible fuzzy fast stock valuation method
Simply take stock reading notes (1/8)
NLP engineer learning summary and index
Language model
Distributed solution - completely solve website cross domain requests
上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花
HiEngine:可媲美本地的云原生内存数据库引擎
开发者,云原生数据库是未来吗?
SAP SEGW 事物码里的导航属性(Navigation Property) 和 EntitySet 使用方法
Using docker for MySQL 8.0 master-slave configuration
【云原生】Nacos中的事件发布与订阅--观察者模式