当前位置:网站首页>函数的默认参数&函数参数的多种方法
函数的默认参数&函数参数的多种方法
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="男生")
边栏推荐
- Free testing of Taobao tmall API order and flag insertion remark interface
- Compile kernel modules separately
- Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
- Redis cluster configuration
- Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
- View and terminate the executing thread in MySQL
- 由扫地增而引起的小叙
- Redis master-slave configuration and sentinel mode
- Simply take stock reading notes (4/8)
- View and modify the MySQL data storage directory under centos7
猜你喜欢
我在滴滴做开源
2021-12-22 transaction record
Iterator details in list... Interview pits
太方便了,钉钉上就可完成代码发布审批啦!
Database connection pool & jdbctemplate
前几年外包干了四年,秋招感觉人生就这样了..
Transactions from December 27 to 28, 2021
SAP UI5 FlexibleColumnLayout 控件介绍
HiEngine:可媲美本地的云原生内存数据库引擎
Transactions from December 29, 2021 to January 4, 2022
随机推荐
【云原生】Nacos-TaskManager 任务管理的使用
A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
Kotlin变量
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces
Language model
RHCSA3
How to connect the API interface of Taobao open platform (super detailed)
超高效!Swagger-Yapi的秘密
SAP 自开发记录用户登录日志等信息
NFT: how to make money with unique assets?
Transactions from January 14 to 19, 2022
Simply take stock reading notes (4/8)
Simply take stock reading notes (2/8)
Taobao flag insertion remarks | logistics delivery interface
I met Tencent in the morning and took out 38K, which showed me the basic smallpox
Free testing of Taobao tmall API order and flag insertion remark interface
Redis cluster configuration
Talk about my drawing skills in my writing career
自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类