列表判断存在不存在的两种方法

方法一:

stus=["哈巴狗","小马","小黑"]
username=input("user:")
count=stus.count(username)
if count>0:
print("该用户已经存在")

方法二:
stus=["哈巴狗","小马","小黑"]
username=input("user:")
if username in stus:#在列表里面  not in 不在列表里面
print("该用户已经存在")

posted on 2018-07-31 14:57  smileBB  阅读(500)  评论(0编辑  收藏  举报