当前位置:网站首页>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 )
边栏推荐
- No response after heartbeat startup
- Supercomputing simulation research has determined a safe and effective carbon capture and storage route
- re. Sub() usage
- JMeter common configuration components and parameterization
- QQ group collection
- First article
- [test theory] test the dimension of professional ability
- Elevator dispatching (pairing project) ①
- Dictionaries and collections
- [machine] [server] Taishan 200
猜你喜欢
Performance test method
Using Lua to realize 99 multiplication table
Canoe: what is vtsystem
Send a request using paste raw text
Installation of ES plug-in in Google browser
Canoe - the second simulation engineering - xvehicle - 2panel design (principle, idea)
Canoe test: two ways to create CAPL test module
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
XMIND installation
[Galaxy Kirin V10] [desktop] FTP common scene setup
随机推荐
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
Local MySQL forgot the password modification method (Windows)
[Galaxy Kirin V10] [server] NUMA Technology
Basic function exercises
Performance test method
Installation of ES plug-in in Google browser
Daemon xinted and logging syslogd
Capl: timer event
[Galaxy Kirin V10] [server] grub default password
Using Lua to realize 99 multiplication table
Safety testing aspects
Canoe - description of common database attributes
1. Circular nesting and understanding of lists
JMeter assembly point technology and logic controller
re. Sub() usage
QQ group collection
Canoe: distinguish VT, VN and vteststudio from their development history
Summary of collection: (to be updated)
Digital simulation beauty match preparation -matlab basic operation No. 6
Software testing related resources