Sep-20-2016, 01:40 AM
I need to know how to use args and kwargs for overloading purposes. Also, if someone knows about generators, explain those to me too.
How do you use *args and **kwargs?
|
Sep-20-2016, 01:40 AM
I need to know how to use args and kwargs for overloading purposes. Also, if someone knows about generators, explain those to me too.
Sep-20-2016, 04:55 AM
There are loads of resource across the internet. Did you have a question?
Sep-20-2016, 02:44 PM
def show_me_the_args(*args, **kwargs): print(args) print('----') print(kwargs) show_me_the_args('spam', 42, fish='cooked', dinner=False) # ('spam', 42) # ---- # {'dinner': False, 'fish': 'cooked'}Does that make sense?
Sep-20-2016, 04:22 PM
*args and **kwargs are shorthand to put positional arguments in a list, and keyword arguments in a dictionary. They work both ways, you can use them in a call (to use a list or a dict instead of separate args)) or in a function definition (so that the function body can iterate the args, or count them)..
A generator is a function that doesn't "return" but that "yield" instead. "Yield" is like return but a subsequent call to the iterator will start on the instruction that follows the yield. Very well explained here.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net |
|