2

I would like to understand why I'm getting different results in these lists operations.

list1 = ['a','b','c']
list1.remove('a')
print(list1) #results ['b', 'c']

text = "abc"
print(list(text).remove('a')) #results Nome
huvdev4
  • 61
  • 5

2 Answers2

2

That is because remove retuns None value. If you try the same thing with the first case, you will observe the same behavior:

list1 = ['a','b','c']
print(list1.remove('a'))
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
0

The list(text).remove('a') operation is in place, is returns None.

You should do this instead:

my_list = list(text)
my_list.remove('a')
print(my_list)
mozway
  • 194,879
  • 13
  • 39
  • 75