[Python] *args and **kwargs (differences between cpp argc argv)
阿新 • • 發佈:2020-12-08
[Python] *args and **kwargs (differences between cpp argc argv)
(
*args
*args refers to those arguments without keywords. What's more, it means that the number of arguments is unknown. The arguments would be stored as a tuple.
**kwargs
**kwargs refers to those keywords arguments, which also means that the number of arguments is unknown. The keywords-arguments would be saved as a dictionary.
It depends on the input arguments when the function is called on.
argc
argument count=len(args)+1
char* args[] or char** args
It's easy to know char* refers to a string.
In this part, each element is stored as a string to store the arguments, the file name is the first argument
#include <iostream> int main(int argc, char** argv) { std::cout << "Have " << argc << " arguments:" << std::endl; for (int i = 0; i < argc; ++i) { std::cout << argv[i] << std::endl; } }
Running it with ./test a1 b2 c3 will output
Have 4 arguments:
./test
a1
b2
c3