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
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
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'))
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)