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

边栏推荐
- Rocky基础知识1
- 155. Minimum stack
- Taobao short videos are automatically released in batches without manual RPA open source
- NFT: how to make money with unique assets?
- I met Tencent in the morning and took out 38K, which showed me the basic smallpox
- Didi open source Delta: AI developers can easily train natural language models
- 研究:数据安全工具在 60% 的情况下无法抵御勒索软件
- How can non-technical departments participate in Devops?
- Association modeling method in SAP segw transaction code
- Install rhel8.2 virtual machine
猜你喜欢

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

SAP UI5 DynamicPage 控件介紹

Actual combat simulation │ JWT login authentication

Pinduoduo flag insertion remarks API

Kotlin variable

SAP SEGW 事物码里的 ABAP 类型和 EDM 类型映射的一个具体例子

MySQL 巨坑:update 更新慎用影响行数做判断!!!

Didi open source Delta: AI developers can easily train natural language models

Taobao order interface | order flag remarks, may be the most stable and easy-to-use interface

A specific example of ABAP type and EDM type mapping in SAP segw transaction code
随机推荐
10 minute fitness method reading notes (1/5)
Difference between JUnit theories and parameterized tests
I'm doing open source in Didi
百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程
HiEngine:可媲美本地的云原生内存数据库引擎
SAP UI5 ObjectPageLayout 控件使用方法分享
Introduction to sap ui5 flexiblecolumnlayout control
【云原生】Nacos-TaskManager 任务管理的使用
Pandora IOT development board learning (HAL Library) - Experiment 7 window watchdog experiment (learning notes)
How to connect the API interface of Taobao open platform (super detailed)
Transactions from December 29, 2021 to January 4, 2022
SAP SEGW 事物码里的 ABAP 类型和 EDM 类型映射的一个具体例子
How can non-technical departments participate in Devops?
What if wechat is mistakenly sealed? Explain the underlying logic of wechat seal in detail
你的下一台电脑何必是电脑,探索不一样的远程操作
《2022年中國銀行業RPA供應商實力矩陣分析》研究報告正式啟動
Lepton 无损压缩原理及性能分析
Simply take stock reading notes (2/8)
Reshape the power of multi cloud products with VMware innovation
将函数放在模块中