当前位置:网站首页>Small case of function transfer parameters
Small case of function transfer parameters
2022-07-05 13:01:00 【South Lake Fishing Song】
''' Write the following function : Function name , be called computer It means calculating The parameters are x,y,method, On behalf of the digital x, Numbers y, character string method If method==add character string , return x+y If method==sub character string , return x-y If method==mul character string , return x*y If method==div character string , return x/y method Set to parameters with default values , Default is default addition Call the call parameters in the following ways Positional arguments Keyword parameters and parameters without default values call '''
def compute(x,y,method = 'add'):
if method == 'add':
print(f'{
x}+{
y}',x+y)
elif method == 'sub':
print(f'{
x}-{
y}',x-y)
elif method == 'mul':
print(f'{
x}*{
y}', x * y)
elif method == 'div':
print(f'{
x}/{
y}', x / y)
compute(3,4,'add')
compute(3,4,'sub')
compute(3,4,'mul')
# If you want to add keyword parameters , It has to be at the end
compute(3,y=4,method='div')
# compute(3,y=4,'sub') # error: An error will be reported if the location parameter is behind the keyword argument
compute(3,4)
compute(x=3,y=4)
边栏推荐
- Laravel document reading notes -mews/captcha use (verification code function)
- 将函数放在模块中
- Hiengine: comparable to the local cloud native memory database engine
- 滴滴开源DELTA:AI开发者可轻松训练自然语言模型
- Four common problems of e-commerce sellers' refund and cash return, with solutions
- How to connect the API interface of Taobao open platform (super detailed)
- Association modeling method in SAP segw transaction code
- 155. 最小栈
- 【云原生】Nacos中的事件发布与订阅--观察者模式
- 我在滴滴做开源
猜你喜欢
[cloud native] event publishing and subscription in Nacos -- observer mode
初识Linkerd项目
Super efficient! The secret of swagger Yapi
简单上手的页面请求和解析案例
Comprehensive upgrade of Taobao short video photosynthetic platform
2021-12-21 transaction record
Distance measuring sensor chip 4530a used in home intelligent lighting
解决uni-app配置页面、tabBar无效问题
RHCSA1
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
随机推荐
155. Minimum stack
DNS的原理介绍
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces
#yyds干货盘点#js截取文件后缀名
解决uni-app配置页面、tabBar无效问题
A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
非技术部门,如何参与 DevOps?
Leetcode20. Valid parentheses
10 minute fitness method reading notes (5/5)
Wechat enterprise payment to change access, open quickly
【云原生】Nacos中的事件发布与订阅--观察者模式
单独编译内核模块
RHCSA1
10 minute fitness method reading notes (2/5)
函数传递参数小案例
Free testing of Taobao tmall API order and flag insertion remark interface
逆波兰表达式
Research: data security tools cannot resist blackmail software in 60% of cases
Actual combat simulation │ JWT login authentication
Pandora IOT development board learning (HAL Library) - Experiment 7 window watchdog experiment (learning notes)