python中有do while循环吗?

问题描述 投票:0回答:1

我是一个初学者,想知道是否有任何机制可以在 python 中执行 while 循环。

我只尝试了 for 和 while 循环,但仍然没有找到任何方法来执行循环体,即使条件仍然为 false。

python loops do-while
1个回答
0
投票

试试这个:

while True:
    user_input = input("Input a string (or 'q' to quit): ")
    if user_input == 'q':
        break
    print(user_input)
© www.soinside.com 2019 - 2024. All rights reserved.