以前是做C++和Java的,刚刚接触Python。在Java和C++中,为了减少函数调用次数,在while或者if语句的判断条件那里直接赋值比较方便。但是在Python中下面代码报错了,想请问Python是不允许这种方式的吗?class Fib(object):
def call(self, num):
L = [] while (length = len(L))<num: if length==0:
L.append(0)
elif length==1:
L.append(1) else:
L.append(L[-1]+L[-2]) return L
f = Fib()print f(10)上述代码的while语句判断条件那里报错
添加回答
举报
0/150
提交
取消