f = lambda # declare a variable f that is a function
n: # that takes an int parameter 'n'
"a"[n:] # if n is 0 return 'a'
or # else
f(n-1) # return a recursive call at n - 1
+ # plus
chr(97+n) # character from code 97 + n
+ # plus
f(n-1) # another recursive call
它的工作原理和其他地方一样。如果
or
的左参数是真的,则表达式的计算结果为真;否则,它的计算结果为右参数。在本例中,"a"[n:]
是n > 0
时的空字符串,因此它等价于我们把它分解一下。你知道吗
相关问题 更多 >
编程相关推荐