擅长:python、mysql、java
<p>正如John Gordon在评论中所说,正确的方法是这样的:</p>
<pre><code>while "https" not in user_url and "http" not in user_url:
</code></pre>
<p>您所拥有的东西不起作用,因为正如您所写的那样,python看到两条语句,必须对它们进行求值才能确定它们是真是假:
1<code>"https"</code>
2.<code>"http" not in user_url</code></p>
<p>非空字符串的真值总是<code>True</code>(可以用<code>bool("somestring")</code>检查)。
因为语句1只是一个字符串,这意味着它总是真的,所以不管您的输入是什么,您最终总是运行循环。你知道吗</p>
<p>一些额外的评论:</em></p>
<p>要检查url,您需要查看“http”是否位于url的开头,因为://google.http.com不是有效的url,因此更好的方法是:<code>while not user_url.startswith("http") and not user_url.startswith("https"):</code></p>