Assigning a function to a variable

前端 未结 5 970
灰色年华
灰色年华 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

    when you perform y=x() you are actually assigning y to the result of calling the function object x and the function has a return value of None. Function calls in python are performed using (). To assign x to y so you can call y just like you would x you assign the function object x to y like y=x and call the function using y()

提交回复
热议问题