In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what the Python function parameter matching model rules keyword-only parameters are, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Python function parameter matching model general rule keyword-only parameter
Overview
Python3's collation of function parameters is more general, namely the Python3 keyword-only parameter, which is a parameter that must be passed only by keyword and not populated with a positional parameter. This rule is useful in dealing with more than one parameter of a person.
Keyword-only
Kword_only (1,2,3, cyste4) print ('-'* 20) kword_only (axi1, cyste3)
Example result:
1 (2, 3) 4-1 () 3
All parameters after * args need to be passed using keywords in the call, otherwise an exception will be thrown.
Def kword_only (a, * b, c): print (a, b, c) kword_only (1,2,3)
Abnormal result:
Kword_only (1,2,3) TypeError: kword_only () missing 1 required keyword-only argument:'c'
We can also use a * character in the parameter list to indicate that the function will not accept a parameter list of variable length, but requires that the parameters that follow * need to be passed using keyword arguments.
Def kword_only (a, *, b, c): print (a, b, c) kword_only (1, baux2, cyste3) print ('-'* 20) kword_only (baux2, cyste3, axi1)
Example result:
1 2 3-1 2 3
We can see that a can be passed using positional parameters, but b and c must be passed through keyword arguments, otherwise an exception will be thrown.
Def kword_only (a, *, b, c): print (a, b, c) kword_only (1,2,3)
Abnormal result:
Kword_only (1,2,3) TypeError: kword_only () takes 1 positional argument but 3 were given
Of course, we can use the default value for the keyword-only parameter, in this case a can still be passed through the position parameter or keyword parameter, while b and c are optional, of course, if you need to pass, you still need to use the keyword parameter to pass.
Def kword_only (a, *, bread2, cymb3): print (a, b, c) kword_only (1) print ('-'* 20) kword_only (axi1) print ('-'* 20) kword_only (bread22, cymb33, aq11)
Example result:
1 2 3-1 2 3-11 22 33
More Python tutorials will be updated later, or if you have any Python tutorials you want to learn, you can leave a message.
On the Python function parameter matching model rules what keyword-only parameters are shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.