当前位置:网站首页>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)

边栏推荐
- 《2022年中國銀行業RPA供應商實力矩陣分析》研究報告正式啟動
- RHCAS6
- RHCSA7
- Super efficient! The secret of swagger Yapi
- Why is your next computer a computer? Explore different remote operations
- A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
- 自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
- 石臻臻的2021总结和2022展望 | 文末彩蛋
- ABAP editor in SAP segw transaction code
- Comprehensive upgrade of Taobao short video photosynthetic platform
猜你喜欢

实战模拟│JWT 登录认证

Taobao short videos are automatically released in batches without manual RPA open source

Distance measuring sensor chip 4530a used in home intelligent lighting
![[cloud native] use of Nacos taskmanager task management](/img/ad/24bdd4572ef9990238913cb7cd16f8.png)
[cloud native] use of Nacos taskmanager task management

SAP UI5 ObjectPageLayout 控件使用方法分享

stirring! 2022 open atom global open source summit registration is hot!

I'm doing open source in Didi

A deep long article on the simplification and acceleration of join operation

Transactions on December 23, 2021

SAP self-development records user login logs and other information
随机推荐
RHCSA4
初识Linkerd项目
stirring! 2022 open atom global open source summit registration is hot!
SAP UI5 FlexibleColumnLayout 控件介绍
946. Verify stack sequence
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces
SAP ui5 objectpagelayout control usage sharing
Free testing of Taobao tmall API order and flag insertion remark interface
国内市场上的BI软件,到底有啥区别
SAP self-development records user login logs and other information
[cloud native] use of Nacos taskmanager task management
Comprehensive upgrade of Taobao short video photosynthetic platform
CF:A. The Third Three Number Problem【关于我是位运算垃圾这个事情】
OpenHarmony应用开发之Navigation组件详解
2021.12.16-2021.12.20 empty four hand transaction records
RHCSA1
insmod 提示 Invalid module format
以VMware创新之道,重塑多云产品力
HiEngine:可媲美本地的云原生内存数据库引擎
Four common problems of e-commerce sellers' refund and cash return, with solutions