当前位置:网站首页>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)
边栏推荐
- A possible investment strategy and a possible fuzzy fast stock valuation method
- Developers, is cloud native database the future?
- 无密码身份验证如何保障用户隐私安全?
- 跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
- Taobao short video, why the worse the effect
- Run, open circuit
- 百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程
- Difference between JUnit theories and parameterized tests
- RHCSA5
- Simply take stock reading notes (2/8)
猜你喜欢
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é.
2021-12-21 transaction record
Detailed explanation of navigation component of openharmony application development
Developers, is cloud native database the future?
Transactions from January 6 to October 2022
RHCSA1
Transactions from December 27 to 28, 2021
10 minute fitness method reading notes (5/5)
From the perspective of technology and risk control, it is analyzed that wechat Alipay restricts the remote collection of personal collection code
百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程
随机推荐
自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
深度长文探讨Join运算的简化和提速
Lepton 无损压缩原理及性能分析
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
HiEngine:可媲美本地的云原生内存数据库引擎
SAP UI5 视图里的 OverflowToolbar 控件
stirring! 2022 open atom global open source summit registration is hot!
[cloud native] use of Nacos taskmanager task management
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Difference between JUnit theories and parameterized tests
[Nacos cloud native] the first step of reading the source code is to start Nacos locally
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é.
What if wechat is mistakenly sealed? Explain the underlying logic of wechat seal in detail
Kotlin function
Introduction to the principle of DNS
你的下一台电脑何必是电脑,探索不一样的远程操作
Wechat enterprise payment to change access, open quickly
Distance measuring sensor chip 4530a used in home intelligent lighting
RHCAS6
Run, open circuit