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

边栏推荐
- Local MySQL forget password modification method (Windows) [easy to understand]
- Safety testing aspects
- Appscan installation steps
- Interview and lecture summary 1
- SSH principle and public key authentication
- Canoe - the third simulation project - bus simulation - 3-2 project implementation
- Climb Phoenix Mountain on December 19, 2021
- [Galaxy Kirin V10] [desktop] FTP common scene setup
- 2021-11-02
- Using SA token to solve websocket handshake authentication
猜你喜欢

OSI model notes
![[Galaxy Kirin V10] [desktop] cannot add printer](/img/a6/28e4aa31e805a018e6db2b32ca1be0.jpg)
[Galaxy Kirin V10] [desktop] cannot add printer

Canoe - the third simulation project - bus simulation - 2 function introduction, network topology

Canoe: what is vtsystem
![[Galaxy Kirin V10] [server] set time synchronization of intranet server](/img/f8/0847314029930840c91bce97ccd961.jpg)
[Galaxy Kirin V10] [server] set time synchronization of intranet server

shell awk

Post man JSON script version conversion
![[Galaxy Kirin V10] [server] NFS setup](/img/ed/bd7f1a1e4924a615cb143a680a2ac7.jpg)
[Galaxy Kirin V10] [server] NFS setup

Application and Optimization Practice of redis in vivo push platform

Installation of ES plug-in in Google browser
随机推荐
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
Hidden C2 tunnel -- use of icmpsh of ICMP
Common system modules and file operations
Xiaobing · beauty appraisal
1. Circular nesting and understanding of lists
Canoe: what is vtsystem
Simple understanding of seesion, cookies, tokens
Function introduction of canbedded component
Summary of automated testing framework
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
Canoe - the third simulation project - bus simulation - 3-2 project implementation
Solaris 10网络服务
Cacti主机模板之定制版
DNS hijacking
Personal thoughts on the development of game automation protocol testing tool
Usage of with as
Send a request using paste raw text
Detailed array expansion analysis --- take you step by step analysis
Software testing related resources
Terms related to hacker technology