python list remove方法实用例子

def types(num):
    try:
        int(num)
        print('输入错误类型名称')
    except ValueError:
        return num


NameList = ['wsg', 'wmj', 'wlj', 'wzj']
for i in range(5):
    NewInput = input('请输入要删除的用户名:').replace(' ', '')
    if types(NewInput) == NewInput:
        if NewInput in NameList:
            NameList.remove(NewInput)
            print('你已经成功删除了{0},未删除的用户为{1}'.format(NewInput,NameList))
        else:
            print('您要删除的用户不存在')
    else:
        pass

一段代码可以有很多种写法,大家可以多去尝试,我们不是孔乙己,只是为了锻炼自己的思维,怎么能写出更好,更加高效的代码!

在路上偶尔的迷茫不要紧,不要一直迷茫,人生很短暂。

猜你喜欢

转载自blog.csdn.net/TianPingXian/article/details/80265894