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

边栏推荐
- DNS的原理介绍
- SAP SEGW 事物码里的 ABAP Editor
- NFT: how to make money with unique assets?
- RHCAS6
- Four common problems of e-commerce sellers' refund and cash return, with solutions
- 155. Minimum stack
- 奔跑,开路
- 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é.
- A deep long article on the simplification and acceleration of join operation
- Taobao flag insertion remarks | logistics delivery interface
猜你喜欢

Install rhel8.2 virtual machine

Introduction aux contrôles de la page dynamique SAP ui5

Overflow toolbar control in SAP ui5 view

RHCAS6

解决 UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa2 in position 107

SAP SEGW 事物码里的导航属性(Navigation Property) 和 EntitySet 使用方法

Principle and performance analysis of lepton lossless compression

Taobao flag insertion remarks | logistics delivery interface

Hiengine: comparable to the local cloud native memory database engine

Distance measuring sensor chip 4530a used in home intelligent lighting
随机推荐
Introduction to sap ui5 flexiblecolumnlayout control
我在滴滴做开源
谈谈我写作生涯的画图技巧
Transactions on December 23, 2021
DNS的原理介绍
Simply take stock reading notes (4/8)
Principle and performance analysis of lepton lossless compression
简单上手的页面请求和解析案例
Free testing of Taobao tmall API order and flag insertion remark interface
ABAP editor in SAP segw transaction code
函数传递参数小案例
开发者,云原生数据库是未来吗?
What is the difference between Bi software in the domestic market
RHCSA1
《信息系统项目管理师》备考笔记---信息化知识
自然语言处理系列(一)入门概述
#yyds干货盘点#js截取文件后缀名
Alipay transfer system background or API interface to avoid pitfalls
函数的默认参数&函数参数的多种方法
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces