June 2019
Beginner to intermediate
770 pages
19h 24m
English
In the previous example, we mapped the rank to a two-tuple of the class and one of the arguments for creating an instance. We can combine class and rank into a partial function. This is a function that has some argument values and is waiting for the final argument value. In many cases, we can use the partial() function from the functools library to create a partial function combining the class object with the rank argument.
The partial() function is not designed to create objects; using it like this will raise an exception. Instead of using the partial function, we can create a lambda object instead. For example, the lambda suit: AceCard("A", suit) expression is a function that is waiting for the suit value to ...
Read now
Unlock full access