我正在尝试传递lambda。
def summation(n, term):
if (n == 0):
return
else:
return summation(n - 1, term) + term
print(summation(5, lambda x: x + 1))
Run Code Online (Sandbox Code Playgroud)
据我了解,lambda x : x + 1将成为term和term将评估到n + 1的功能,但是这是行不通的。谁能向我解释?
I was wondering how something like this would work.
int[] a = {5, 3, 4};
int[] b = {3, 4, 5};
a = b;
Run Code Online (Sandbox Code Playgroud)
Does this mean that a will now reference b.
So if I do a[0] it will be 3?
Also if this is the case what happens to the items in the old array?
为什么这样做:
def make_fib():
cur, next = 0, 1
def fib():
nonlocal cur, next
result = cur
cur, next = next, cur + next
return result
return fib
Run Code Online (Sandbox Code Playgroud)
工作方式不同于:
def make_fib():
cur, next = 0, 1
def fib():
nonlocal cur, next
result = cur
cur = next
next = cur + next
return result
return fib
Run Code Online (Sandbox Code Playgroud)
我看到第二个怎么弄乱了,因为在cur = next和next = cur + next时,因为本质上它将变成next = next + next,但是第一个为什么运行不同?