Can the Python language assign values in judgment statements?

I used to do CPP and Java, but I just came into contact with Python. In Java and CPP, in order to reduce the number of function calls, it is convenient to assign values directly to the judgment conditions of while or if statements. But in Python the following code reported an error, would you like to ask Python does not allow this way?

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)

the while statement judgment condition of the above code where the error is reported

Apr.25,2021

python3.7 is a
that can be assigned in a conditional statement. Versions of python before

cannot be

.
Menu