<p>我是Python新手,在输入验证方面遇到了问题。具体来说,我要求用户输入一个URL,但我要确保他们输入的是“http”或“https”作为URL的一部分。这就是我一直在做的:</p>
<pre><code>user_url = raw_input(please enter your URL: )
while "https" or "http" not in user_url:
print "you must enter a valid URL format, try again"
user_url = raw_input(please enter your URL: )
</code></pre>
<p>当我使用这段代码时,任何文本仍然被接受,即使它不包含“http”或“https”。任何帮助都将不胜感激。谢谢。你知道吗</p>
<p>您应该使用:</p>
<pre><code>user_url = raw_input("please enter your URL: ")
while user_url.find("http") != -1:
print "you must enter a valid URL format, try again"
user_url = raw_input("please enter your URL: ")
</code></pre>