Emulate a do-while loop in Python?

后端 未结 16 1050
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 06:47

I need to emulate a do-while loop in a Python program. Unfortunately, the following straightforward code does not work:

list_of_ints = [ 1, 2, 3 ]
iterator =         


        
16条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 07:24

    Python 3.8 has the answer.

    It's called assignment expressions. from the documentation:

    # Loop over fixed length blocks
    while (block := f.read(256)) != '':
        process(block)
    

提交回复
热议问题