当前位置:网站首页>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)
边栏推荐
- [cloud native] use of Nacos taskmanager task management
- Alipay transfer system background or API interface to avoid pitfalls
- 2021.12.16-2021.12.20 empty four hand transaction records
- Introduction to sap ui5 dynamicpage control
- RHCSA5
- 单独编译内核模块
- 2021-12-22 transaction record
- Le rapport de recherche sur l'analyse matricielle de la Force des fournisseurs de RPA dans le secteur bancaire chinois en 2022 a été officiellement lancé.
- Taobao flag insertion remarks | logistics delivery interface
- 研究:数据安全工具在 60% 的情况下无法抵御勒索软件
猜你喜欢
解决uni-app配置页面、tabBar无效问题
PyCharm安装第三方库图解
Alipay transfer system background or API interface to avoid pitfalls
Lepton 无损压缩原理及性能分析
Pinduoduo flag insertion remarks API
I'm doing open source in Didi
《2022年中國銀行業RPA供應商實力矩陣分析》研究報告正式啟動
逆波兰表达式
Concurrent performance test of SAP Spartacus with JMeter
ABAP editor in SAP segw transaction code
随机推荐
开发者,云原生数据库是未来吗?
[Nacos cloud native] the first step of reading the source code is to start Nacos locally
SAP UI5 DynamicPage 控件介绍
Rocky基础知识1
Simply take stock reading notes (2/8)
Simply take stock reading notes (3/8)
单独编译内核模块
Transactions from December 27 to 28, 2021
A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
HiEngine:可媲美本地的云原生内存数据库引擎
946. 验证栈序列
Introduction aux contrôles de la page dynamique SAP ui5
Comprehensive upgrade of Taobao short video photosynthetic platform
【云原生】Nacos中的事件发布与订阅--观察者模式
Distance measuring sensor chip 4530a used in home intelligent lighting
ABAP editor in SAP segw transaction code
Alibaba cloud SLB load balancing product basic concept and purchase process
How to connect the API interface of Taobao open platform (super detailed)
Kotlin function
155. Minimum stack