Partial Function in Python
Level 4165 keystrokes
This creates partial functions with pre-filled arguments. The partial() function fixes some arguments of a function.
Python code
# Import partial from functools module1from functools import partial2 # Define a function that calculates power3def power(base, exp): # Return base raised to exponent4 return base ** exp5 # Create partial function with exp fixed to 26square = partial(power, exp=2)# Create partial function with exp fixed to 37cube = partial(power, exp=3)8 # Call square(5) which is power(5, exp=2) = 259print(square(5))# Call cube(3) which is power(3, exp=3) = 2710print(cube(3))Output
25 27
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
(× 7)× 7=× 4,× 3*× 2:× 1