【发布时间】:2015-01-09 21:49:29
【问题描述】:
from pythonds.basic.stack import Stack
rStack = Stack()
def toStr(n,base):
convertString = "0123456789ABCDEF"
while n > 0:
if n < base:
rStack.push(convertString[n])
else:
rStack.push(convertString[n % base])
n = n // base
res = ""
while not rStack.isEmpty():
res = res + str(rStack.pop())
return res
print(toStr(1345,2))
我指的是this tutorial 并粘贴了上面的代码。该教程说该函数是递归的,但我在任何地方都看不到递归调用,只是一个while循环。我错过了什么?
【问题讨论】:
-
天哪,本教程的作者从未听说过 PEP-8?
-
@IanAuld 有什么问题?代码可读性很强。
-
C/C++ doThis(可能还有其他一些),Python does_this。更具可读性。 BDFL 规定了它,所以我们必须遵守 :-)。