怎么写才能在比较时候不区分大小写?Lion和liON不区分大小写对比,并打印出已被占用。

current_users = ['Tifa', 'Ada', 'Lightning', 'Lion', 'Natasha']

new_users = ['Tifa', 'Ada', 'Lucifer', 'liON', 'Michael']

#下面是我写的代码,该如何在用户名为liON时打印出'Username is uese'?

for new_user in new_users:

    print(new_user)

    if new_user in current_users:

        print('Username is uesd')

    else:

        print('Username is not used')


Good丶study
浏览 1257回答 1
1回答

Good丶study

current_users = ['Tifa', 'Ada', 'Lightning', 'Lion', 'Natasha']new_users = ['Tifa', 'Ada', 'Lucifer', 'liON', 'Michael']for new_user in new_users:    print(new_user)    if new_user.lower() in [value.lower() for value in current_users]:        print('You need another name!')    else:        print('You can use this name!')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python