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

边栏推荐
- Canoe - the third simulation project - bus simulation-1 overview
- Performance features focus & JMeter & LoadRunner advantages and disadvantages
- VI text editor and user rights management, group management and time management
- Local MySQL forgot the password modification method (Windows)
- Canoe - the third simulation project - bus simulation - 3-2 project implementation
- Take advantage of the world's sleeping gap to improve and surpass yourself -- get up early
- Advanced order of function
- Notes on writing test points in mind mapping
- 2、 Operators and branches
- 51 data analysis post
猜你喜欢

Oracle11g | getting started with database. It's enough to read this 10000 word analysis

SQL greatest() function instance detailed example

JMeter common configuration components and parameterization

Digital simulation beauty match preparation -matlab basic operation No. 6
![[Galaxy Kirin V10] [desktop] cannot add printer](/img/a6/28e4aa31e805a018e6db2b32ca1be0.jpg)
[Galaxy Kirin V10] [desktop] cannot add printer

DNS hijacking

Canoe - the third simulation project - bus simulation - 2 function introduction, network topology
![[Galaxy Kirin V10] [desktop] build NFS to realize disk sharing](/img/72/5e725a44a50f152b477a4b2907a2d0.jpg)
[Galaxy Kirin V10] [desktop] build NFS to realize disk sharing

Using SA token to solve websocket handshake authentication

20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13
随机推荐
[Galaxy Kirin V10] [server] soft RAID configuration
Basic function exercises
JMeter correlation technology
Post man JSON script version conversion
Solaris 10 network services
Day7 list and dictionary jobs
Canoe - the second simulation project -xvihicle1 bus database design (operation)
守护进程Xinted和日志记录Syslogd
Postman interface test
Digital simulation beauty match preparation -matlab basic operation No. 6
[Galaxy Kirin V10] [server] system startup failed
三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?
Test question bank management system - database design [easy to understand]
2、 Operators and branches
Regular expression
Elevator dispatching (pairing project) ②
Appscan installation steps
CAPL: on sysVar_ Update difference on sysvar
Advanced order of function
1. Circular nesting and understanding of lists