Assign variable in while loop condition in Python?

前端 未结 11 1565
名媛妹妹
名媛妹妹 2020-12-08 03:39

I just came across this piece of code

while 1:
    line = data.readline()
    if not line:
        break
    #...

and thought, there must

11条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 04:19

    According to the FAQ from Python's documentation, iterating over the input with for construct or running an infinite while True loop and using break statement to terminate it, are preferred and idiomatic ways of iteration.

提交回复
热议问题