Python
This page helps with python and general programming tips you may not know:
'*' and '**' Operators
The single star *
unpacks the sequence/collection into positional arguments, so you can do this:
This will unpack the tuple so that it actually executes as:
The double star **
does the same, only using a dictionary and thus named arguments:
You can also combine:
will execute as:
Additionally you can define functions to take *x
and **y
arguments, this allows a function to accept any number of positional and/or named arguments that aren't specifically named in the declaration.
Example:
or with **
:
this can allow you to specify a large number of optional parameters without having to declare them.
And again, you can combine:
Yield and Generators
Last updated