Removing a string from a list

后端 未结 4 854
抹茶落季
抹茶落季 2021-01-16 04:04

I create a list, and I want to remove a string from it.

Ex:

>>> myList = [\'a\', \'b\', \'c\', \'d\']   
>>> myList = myList.remove         


        
4条回答
  •  半阙折子戏
    2021-01-16 04:34

    Remember that lists are mutable, so you can simply call remove on the list itself:

    >>> myList = ['a', 'b', 'c', 'd']
    >>> myList.remove('c')
    >>> myList
    ['a', 'b', 'd']
    

    The reason you were getting None before is because remove() always returns None

提交回复
热议问题