当前位置:网站首页>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
- Advanced order of function
- [Galaxy Kirin V10] [server] system startup failed
- 守护进程Xinted和日志记录Syslogd
- Failed to configure a DataSource: ‘url‘ attribute is not specified... Bug solution
- 3W word will help you master the C language as soon as you get started - the latest update is up to 5.22
- [Galaxy Kirin V10] [server] FTP introduction and common scenario construction
- Detailed array expansion analysis --- take you step by step analysis
- Summary of collection: (to be updated)
- 三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?
猜你喜欢
Canoe - the third simulation project - bus simulation - 3-2 project implementation
Summary of collection: (to be updated)
Usage of case when then else end statement
[machine] [server] Taishan 200
[Galaxy Kirin V10] [desktop] can't be started or the screen is black
[Galaxy Kirin V10] [desktop] FTP common scene setup
Discussion | has large AI become autonomous? Lecun, chief scientist of openai
Digital simulation beauty match preparation -matlab basic operation No. 6
Elevator dispatching (pairing project) ②
Postman interface test
随机推荐
[Galaxy Kirin V10] [server] system startup failed
Postman interface test
2022 ape circle recruitment project (software development)
Object. Assign () & JS (= >) arrow function & foreach () function
Customized version of cacti host template
JMeter Foundation
Some tips on learning database
三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?
Swagger and OpenAPI
Software testing related resources
Elevator dispatching (pairing project) ③
Post man JSON script version conversion
Appscan installation steps
Day06 list job
Locust installation
Failed to configure a DataSource: ‘url‘ attribute is not specified... Bug solution
Using Lua to realize 99 multiplication table
I What is security testing
Canoe - the third simulation project - bus simulation - 3-1 project implementation
QQ group administrators