这个问题在这里已有答案:
我现在正在学习一些python,所以我是初学者,我有一个带有“current_users”的列表,还有一个带有“new_users”的列表,我希望不必重复用户名,所以如果用户名(例如John) )在current_users和new_users中,程序打印“更改你的用户名”,但问题是如果new_users有“John”和current_users“JOHN”,程序不打印该字符串,因为它认为它们是2个不同的用户名,我已经尝试使用.lower()降低new_users中的名称,但我不知道如何使用当前的名称来做同样的事情。
current_users = ["Carlo", "carla", "FRANCESCO", "giacomo"]
new_users = ["carlo", "Francesco", "luca", "gabriele"]
for new in new_users:
if new.lower() in current_users:
print("Change your username")
else:
print("Welcome!")
我希望程序为每个已经使用过的名称输出“更改用户名”
您需要强制转换以降低新用户名和当前用户。
current_users = ["Carlo", "carla", "FRANCESCO", "giacomo"]
new_users = ["carlo", "Francesco", "luca", "gabriele"]
for new in new_users:
if new.lower() in [current.lower() for current in current_users]:
print("Change your username")
else:
print("Welcome!")