Home > Article > Backend Development > What are the forms of defining variable parameters in Python?
Instructions
1. Add * before the formal parameters in the format of *args.
This means creating an empty tuple named args, which can accept any external non-keyword arguments passed in. Ordinary arguments must be passed as non-keyword arguments, otherwise the Python interpreter will preferentially pass all arguments to variadic arguments.
2. **kwargs means creating an empty dictionary named kwargs, which can accept any number of actual parameters assigned with keyword parameters.
Examples
def calc(*numbers): sum = 0 for n in numbers: sum = sum + n return sum print(calc(10, 9))
1. Simple and easy to use, compared with traditional languages such as C/C, Java, and C# , Python’s requirements for code format are not so strict;
2. Python is open source, everyone can see the source code, and can be transplanted and used on many platforms;
3 , Python is object-oriented and can support process-oriented programming and object-oriented programming;
4. Python is an interpreted language. Programs written in Python do not need to be compiled into binary code and can be run directly from source code. Program;
5. Python is powerful and has many modules, which can basically realize all common functions.
The above is the detailed content of What are the forms of defining variable parameters in Python?. For more information, please follow other related articles on the PHP Chinese website!