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

边栏推荐
- 无密码身份验证如何保障用户隐私安全?
- 事务的基本特性和隔离级别
- RHCAS6
- 滴滴开源DELTA:AI开发者可轻松训练自然语言模型
- Comprehensive upgrade of Taobao short video photosynthetic platform
- Pinduoduo flag insertion remarks API
- A possible investment strategy and a possible fuzzy fast stock valuation method
- 百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程
- Halcon 模板匹配实战代码(一)
- 非技术部门,如何参与 DevOps?
猜你喜欢

非技术部门,如何参与 DevOps?

滴滴开源DELTA:AI开发者可轻松训练自然语言模型

解决uni-app配置页面、tabBar无效问题
![[Nacos cloud native] the first step of reading the source code is to start Nacos locally](/img/f8/d9b848593cf7380a6c99ee0a8158f8.png)
[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é.

Notes for preparation of information system project manager --- information knowledge

946. 验证栈序列

Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue

Setting up sqli lab environment

SAP UI5 视图里的 OverflowToolbar 控件
随机推荐
初识Linkerd项目
Principle and performance analysis of lepton lossless compression
MySQL giant pit: update updates should be judged with caution by affecting the number of rows!!!
Free testing of Taobao tmall API order and flag insertion remark interface
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
CVPR 2022 | single step 3D target recognizer based on sparse transformer
I met Tencent in the morning and took out 38K, which showed me the basic smallpox
Discussion on error messages and API versions of SAP ui5 getsaplogonlanguage is not a function
Rocky basics 1
Alipay transfer system background or API interface to avoid pitfalls
10 minute fitness method reading notes (5/5)
Halcon template matching actual code (I)
LeetCode20.有效的括号
It's too convenient. You can complete the code release and approval by nailing it!
逆波兰表达式
函数的默认参数&函数参数的多种方法
Taobao order interface | order flag remarks, may be the most stable and easy-to-use interface
Natural language processing from Xiaobai to proficient (4): using machine learning to classify Chinese email content
HiEngine:可媲美本地的云原生内存数据库引擎
简单上手的页面请求和解析案例