+ 1

Args and kwargs

I am unable to understand use of args and kwargs in python.

1st Apr 2024, 4:13 AM
Vivek Maurya
Vivek Maurya - avatar
3 Respuestas
+ 3
*args is like a box that holds many things (positional arguments), and **kwargs is like a magical book where you can write down any information (keyword arguments) you want. They help make functions more flexible by allowing them to handle different numbers of arguments and keyword arguments.
1st Apr 2024, 5:02 AM
KAVASKAR S
KAVASKAR S - avatar
+ 3
Vivek Maurya , we can not only use args for functions in codes, but also when running a python script from the *command line* (passing command-line arguments to the script). these arguments can be accessed within the python code (by using modules like `sys` or `argparse`) and can be used to customize the behavior of the script, based on the provided input.
1st Apr 2024, 6:07 AM
Lothar
Lothar - avatar