In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the example analysis of the crystal ball function in python, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Pass actual parameter
There may be many formal parameters in a function definition. Therefore, multiple arguments can also be included in the process of function call. There are many ways to pass arguments to a function. Positional arguments can be used if the order of arguments is the same as that of formal parameters. You can also use keyword arguments, where each argument consists of a variable name and a value.
Location argument
When calling a function, python must associate each argument in the function call to a parameter in the function definition, that is, the argument is passed according to the parameter name. The simplest way to associate the argument is the order of the argument, which is the location argument.
Def cale (c=a+b return b): c=a+b return c result=cale (6 min8) print (result)
In the code block above, we first use the defstatement to create a function named cale, which is defined in the parenthesis operator after the function name, occupying the position of the two actual parameters. So an and b occupy the position of the actual value, so it's called a parameter. A _ r b is called formal parameter for short. The position of the formal parameter is usually at the definition of the function, so we add two formal parameters to the parentheses after the def function. In the lower result=cale (6 and 8), 6 and 8 are called the values of the actual parameters, or arguments for short, and the position of the arguments appears at the call to the function.
fourteen
As shown above, we can see that 6 is passed to a, and from 8 to b. This is passed by location. Because 6 is in the first position of the argument. And an is in the first position of the parameter, so 6 is passed to a, that is, asides 6. Similarly, 8 is in the second position of the argument and b is in the second position of the definition. So c=a+b is 14. 5%.
Keyword parameter
The name key-value pair passed to the function when the keyword argument is real. Associate the name and value directly in the argument. Therefore, there is no confusion when passing arguments to the function. Keyword arguments can be ignored, and the order of arguments in function calls can clearly indicate that each function call is worth using.
Def cale (aformab): c=a+b return c result=cale (baked 6 menagerie 8) print (result
fourteen
Because in the argument, the value of b is 6, the assignment of an is 8, the value of b at the definition is 6, so the value of b is 6, and the assignment of an is 9, so the value of an is 8.
Default parameter values for function definition
Set the default value for the parameter when the function is defined, and the argument needs to be passed only if it does not match the default value.
Definition of function parameters
Variable number of position parameters
(1) when defining a function, you may not be able to determine the number of location arguments passed in advance, using variable position parameters.
(2) use * to define a variable number of position parameters.
(3) the result is a tuple.
Def new (* args): print (args) new (10) new (11 mine22, 33) (10,) (11, 22, 33) variable number of key word parameters
The main results are as follows: (1) when defining a function, it is impossible to determine the number of keyword arguments passed in advance.
(2) use * to define a variable number of keyword parameters.
(3) the result is a dictionary.
Def new (* * args): print (args) new (aq10) new (aq11pr baud 22 pint 33) {'aqu: 10} {'aqu: 11, 'baked: 22,' catered: 33} these are all the contents of this article entitled "sample Analysis of Crystal Ball functions in python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.