In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares with you is about the default value of python function parameters and how to call parameters. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Getting started with python-default values of function parameters and calls to parameters
Default setting of function parameters
Enter:
#! / usr/bin/python
# Filename: func_default.py
Def say (message, times = 1):
Print (message * times)
Say ('Hello')
Say ('World', 5)
Output:
Hello
WorldWorldWorldWorldWorld
Explanation:
When a function is defined, the parameters after the function can set default values. When the function is called, the parameter with the default value has been set, and the default value can be replaced if it is assigned.
In this case, the default value of 1 is used for the first call, so a set of contents is output.
The second call reassigns 5, so five sets of content are output.
Note:
During a function call, all parameters must be declared.
The call of function parameters
Enter:
#! / usr/bin/python # Filename: func_key.py
Def func (a, baked 5, cased 10):
Print ('an is', a, 'and b is', b,' and c is', c)
# function call
Func (3,7)
Func (25, censor 24)
Func (cantilever 50, astat100)
Output:
$python func_key.py
An is 3 and b is 7 and c is 10
An is 25 and b is 5 and c is 24
An is 100 and b is 5 and c is 50
Explanation:
If there are many parameters in the function, but you only want to specify some of them, you can assign values to those parameters by naming them-this is called keyword arguments
Parameters that do not use a name (keyword) specify the parameters of the function by location.
In this case, the call to the function can be assigned through keyword parameters.
Advantages:
It's easier to use functions because we don't have to worry about the order of the parameters.
As long as other parameters have default parameter values, we can assign values to only those parameters we want.
These are the default values of python function parameters and how to call them. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.