当前位置:网站首页>函数的默认参数&函数参数的多种方法
函数的默认参数&函数参数的多种方法
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="男生")
边栏推荐
- JDBC -- use JDBC connection to operate MySQL database
- CF:A. The Third Three Number Problem【关于我是位运算垃圾这个事情】
- Talk about my drawing skills in my writing career
- What is the difference between Bi software in the domestic market
- Neural network of PRML reading notes (1)
- Pinduoduo flag insertion remarks API
- Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
- Annotation problem and hidden Markov model
- Redis master-slave configuration and sentinel mode
- Language model
猜你喜欢
A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
SAP UI5 FlexibleColumnLayout 控件介绍
石臻臻的2021总结和2022展望 | 文末彩蛋
VoneDAO破解组织发展效能难题
Laravel文档阅读笔记-mews/captcha的使用(验证码功能)
实战模拟│JWT 登录认证
Talk about my drawing skills in my writing career
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
SAP UI5 视图里的 OverflowToolbar 控件
在家庭智能照明中应用的测距传感芯片4530A
随机推荐
How can non-technical departments participate in Devops?
国内市场上的BI软件,到底有啥区别
开发者,云原生数据库是未来吗?
Notes for preparation of information system project manager --- information knowledge
Storage Basics
RHCSA1
Comprehensive upgrade of Taobao short video photosynthetic platform
Distributed solution - completely solve website cross domain requests
Transactions from January 6 to October 2022
[cloud native] use of Nacos taskmanager task management
ActiveMQ installation and deployment simple configuration (personal test)
CF:A. The Third Three Number Problem【关于我是位运算垃圾这个事情】
超高效!Swagger-Yapi的秘密
单独编译内核模块
Flume common commands and basic operations
Lepton 无损压缩原理及性能分析
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces
深度长文探讨Join运算的简化和提速
以VMware创新之道,重塑多云产品力
跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式