当前位置:网站首页>函数的默认参数&函数参数的多种方法
函数的默认参数&函数参数的多种方法
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="男生")
边栏推荐
- Transactions from December 27 to 28, 2021
- Annotation problem and hidden Markov model
- Add a new cloud disk to Huawei virtual machine
- HiEngine:可媲美本地的云原生内存数据库引擎
- Kotlin变量
- Neural network of PRML reading notes (1)
- SAP UI5 DynamicPage 控件介绍
- Talk about my drawing skills in my writing career
- 奔跑,开路
- 太方便了,钉钉上就可完成代码发布审批啦!
猜你喜欢

How can non-technical departments participate in Devops?

10 minute fitness method reading notes (3/5)

国内市场上的BI软件,到底有啥区别

前几年外包干了四年,秋招感觉人生就这样了..

JDBC -- extract JDBC tool classes

解决 UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa2 in position 107

在家庭智能照明中应用的测距传感芯片4530A

初识Linkerd项目

Taobao order interface | order flag remarks, may be the most stable and easy-to-use interface

《信息系统项目管理师》备考笔记---信息化知识
随机推荐
Vonedao solves the problem of organizational development effectiveness
Lepton 无损压缩原理及性能分析
##无监控,不运维,以下是监控里常用的脚本监控
Super efficient! The secret of swagger Yapi
Taobao flag insertion remarks | logistics delivery interface
使用 jMeter 对 SAP Spartacus 进行并发性能测试
Kotlin流程控制、循环
Kotlin variable
太方便了,钉钉上就可完成代码发布审批啦!
Alipay transfer system background or API interface to avoid pitfalls
Annotation problem and hidden Markov model
Shi Zhenzhen's 2021 summary and 2022 outlook | colorful eggs at the end of the article
Time conversion error
How to connect the API interface of Taobao open platform (super detailed)
你的下一台电脑何必是电脑,探索不一样的远程操作
About LDA model
逆波兰表达式
Using MySQL in docker
Didi open source Delta: AI developers can easily train natural language models
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces