Through the previous study, we have learned how to customize functions in Python. Today we will talk about params in Python function parameters
If we already know the number of function parameters, we can just pass it to the function directly, but in most cases , we don’t know the number of function parameters, how to solve this? This uses the params parameters in Python!
PythonThe parameter collection mechanism uses the asterisk "*" to implement . Here, a "*" is added in front of the specified parameter params. "*" means to use params parameters to collect An indefinite number of parameters are passed in, and the collected parameters are stored in params in the form of tuples. If no parameters are passed in, params is an empty tuple
For example
As you can see from the above, no matter how many parameters are passed to the function, it will work well through the params parameter collection mechanism. solution!
Related learning recommendations: python tutorial
The above is the detailed content of What are params in python. For more information, please follow other related articles on the PHP Chinese website!