def main():
user = input('enter a user: ')
data = ['john','gogo','baby','user']
if user not in data:
#stop the rest of the code
print (user)
main()
假设用户输入不在列表中的“johnny”不会(在我的情况下)while循环是正确的吗?Python3如果发生什么事,不要做这部分代码
def main():
user = input('enter a user: ')
data = ['john','gogo','baby','user']
if user not in data:
#stop the rest of the code
print (user)
main()
假设用户输入不在列表中的“johnny”不会(在我的情况下)while循环是正确的吗?Python3如果发生什么事,不要做这部分代码
添加return语句将结束该行上的函数。
def main():
user = input('enter a user: ')
data = ['john','gogo','baby','user']
if user not in data:
#stop the rest of the code
return
print (user)
main()
我看到您的评论,你想'发送它到另一个功能'。您可以编写另一个函数并在“返回”之前调用它。如果这没有意义,你可能想要做一些Python /编程教程。 –
我知道如何将它发送到另一个函数,但我想知道是否可以使用break语句停止它,如果它不在它而不是返回? –
当您有循环时使用break语句。你在这里没有使用循环,所以break语句不适合使用。你想做什么让你觉得你需要一个突破声明?你需要回到main()吗?在这种情况下,只需省略return语句,并在您的其他函数返回后继续执行main。 –
可以接近它这个另一种方式:
if user in data:
然后你就可以把你的代码,这if statement
后,如果user
是data
的代码才会执行。
对不起,我不明白你的问题。什么时候循环? –
@vaibhav骡我修好了 –
仍然没有while循环。你究竟需要知道什么? – HelloWorld