while true循环python输入数据的个数_他们是怎么从这个while-true循环中跳出来的?...

在我的理解中while True:永远的平均循环,like saying while True == True。

还有一种机制可以使用break语句打破无限循环。

我在the cs50 module中遇到一个函数,它使用while循环(持续提示输入int),其中没有中断。

我试图理解,当我们输入一个int时,循环中的“True语句”会变成False(我就是这么理解它的),然后停止提示用户。在

换句话说,在代码中什么可以将whiletrue改为false?在

其功能如下:def get_long(prompt=None):

"""

Read a line of text from standard input and return the equivalent long;

if text does not represent a long, user is prompted to retry. If line

can't be read, return None.

"""

while True:

s = get_string(prompt)

if s is None:

return None

if re.search(r"^[+-]?\d+$", s):

try:

return long(s, 10)

except ValueError:

pass

# temporarily here for backwards compatibility

if prompt is None:

print("Retry: ", end="")

内部使用的get_string()函数如下:

^{pr2}$

当我把一个字符串转换成一个真的字符串时,如何才能得到一个字符串呢?

有人能给我解释一下吗,也许我遗漏了while True:语句。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值