1
我正在python中创建一个手机注册表,用户可以选择将新人添加到注册表中。我需要获取代码以查找该用户是否已经在注册中。我的对象具有surname
,firstname
,phonenumber
和address
的属性。如何在对象列表中搜索属性?
我的代码如下所示:
def personInRegister(surname, firstname, phonenumber, address):
matchInRegister = False
x = 0
while x in range(len(people)):
if (people[x].surname.lower == surname.lower and
people[x].firstname.lower == firstname.lower and
people[x].phonenumber == phonenumber and
people[x].address.lower == address.lower):
matchInRegister = True
break
else:
x = x+1
return matchInRegister
那里的人是我的人名单。
我没有得到它的工作,我不知道我做错了什么。请帮忙!
'str.lower'是一个函数。 'str.lower()'调用函数并返回字符串的小写版本。 –