为什么我需要返回True或false?

时间:2020-01-17 09:35:51

标签: python

为什么会说登录成功 并没有返回True / False,登录就不会成功?

def passwords(name,password):
  data = [("Peter", "thepeter"), ("James", "thejames")]
  for x in data:
    if x[0]==name and x[1]==password:
      print("Login successful")
      return True
    else:
      print("Login not successful")
      return False
name1=input("Name:")
password1=input("Password:")
passwords(name1,password1)

1 个答案:

答案 0 :(得分:0)

虽然它确实打印“登录成功/不成功”,但是如果您使用return,也可以使用如下功能:

a = passwords(someone, password)

现在,如果它返回True,则a将是True。 如果它返回False,则a将是False