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()'調用函數並返回字符串的小寫版本。 –