Assigning a function to a variable

前端 未结 5 964
灰色年华
灰色年华 2020-11-28 06:24

Let\'s say I have a function

def x():
    print(20)

Now I want to assign the function to a variable called y, so that if I us

5条回答
  •  醉酒成梦
    2020-11-28 07:15

    lambda should be useful for this case. For example,

    1. create function y=x+1 y=lambda x:x+1

    2. call the function y(1) then return 2.

提交回复
热议问题