小编JDS*_*044的帖子

在中途停止while循环 - Python

通过语句在Python中途停止'while'循环的最佳方法是什么?我知道,break但我认为使用这将是不好的做法.

例如,在下面的代码中,我只希望程序打印一次,而不是两次...

variable = ""
while variable == "" :
    print("Variable is blank.")

    # statement should break here...

    variable = "text"
    print("Variable is: " + variable)
Run Code Online (Sandbox Code Playgroud)

你能帮我吗?提前致谢.

python variables break while-loop python-3.x

-1
推荐指数
1
解决办法
1608
查看次数

标签 统计

break ×1

python ×1

python-3.x ×1

variables ×1

while-loop ×1