当前位置:网站首页>Function parameters (positional parameters, default value parameters, variable parameters, named keyword parameters, keyword parameters)
Function parameters (positional parameters, default value parameters, variable parameters, named keyword parameters, keyword parameters)
2022-07-04 11:08:00 【It's a cinch!】
Positional arguments :
Argument and formal parameter positions , One-to-one correspondence
Default parameter :
Set the default value for a parameter of the formal parameter , If this parameter does not pass in the corresponding value , Calculate by default , If the corresponding value is passed in , Calculate according to the value passed in

※ The default value parameter is written later
※ Formal parameters are not necessary Don't point to a mutable object ( Such as ,list、set、tuple)
※ So avoid the above situation , The default value parameter must point to an immutable object ( Such as ,None)

Variable parameters : * Variable name ( It could be a variable , List name 、 Tuple name )
Pass in 0 Two or more parameters , Encapsulate the parameters into Tuples
* Represents a variable parameter

Key parameters : ** Variable name
Pass in 0 Two or more parameters , Encapsulate the parameters into Dictionaries
** Represents a variable parameter


Named key parameters :

person(" Zhang San ",19," Beijing "," male ") Error reason : Is there no named keyword , The system defaults to position parameters ,person(name,age,*,city,gender) The function has only two positional arguments , So there's an error .
Add :
1. If variable parameters already appear in function parameters (*),
You can omit named keywords *( Because variable parameters can be transferred , Don't pass it on )

2. You can set default values for named keyword parameters

Parameter combination :
Five parameter types can be combined , But there is a certain order ( Positional arguments 、 Default parameter 、 Variable parameters 、 Named key parameters 、 Key parameters )

边栏推荐
- CAPL: on sysVar_ Update difference on sysvar
- Automatic translation between Chinese and English
- MBG combat zero basis
- Capl: timer event
- Canoe-the second simulation project-xvehicle-1 bus database design (idea)
- Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early
- Usage of case when then else end statement
- Heartbeat启动后无反应
- VPS安装Virtualmin面板
- Using SA token to solve websocket handshake authentication
猜你喜欢

JMeter assembly point technology and logic controller

Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)

Introduction to Lichuang EDA

Installation of ES plug-in in Google browser

QQ group administrators

Fundamentals of software testing

Canoe - the second simulation engineering - xvehicle - 2panel design (principle, idea)

Automatic translation between Chinese and English

Replace() function

Oracle11g | getting started with database. It's enough to read this 10000 word analysis
随机推荐
Hidden C2 tunnel -- use of icmpsh of ICMP
Heartbeat报错 attempted replay attack
R built in data set
Digital simulation beauty match preparation -matlab basic operation No. 6
Climb Phoenix Mountain on December 19, 2021
Day06 list job
3W word will help you master the C language as soon as you get started - the latest update is up to 5.22
Performance test overview
[Galaxy Kirin V10] [desktop] cannot add printer
Postman advanced
QQ group collection
Get the data of the top 100 headlines today with Tianxing data
XMIND installation
TS type gymnastics: illustrating a complex advanced type
unit testing
Common system modules and file operations
Jemeter plug-in technology
Cacti主机模板之定制版
Replace() function
Oracle11g | getting started with database. It's enough to read this 10000 word analysis