Function restriction by fixing an argument
问题 How should I make function with lesser dimensionality than the original one by fixing an argument of it: For example I want to make successor function out of sum function as follows: def add(x,y): return x+y Now I am looking for something like this: g=f(~,1) which would be the successor function, i.e. g(x)=x+1 . 回答1: You can write your own function: def g(y): return f(2, y) Or more concisely: g = lambda y: f(2, y) There's also functools.partial : import functools def f(x, y): return x + y g =