Why I cannot apply .remove() method to list in python?
Question:
Answers:
remove()
does not return anything. Or, perhaps to be more precise, it returns None
. You’re removing 'c'
from the my_list and then setting the no_c_list to None
.
my_list = ['a', 'b', 'c']
my_list.remove('c')
print(my_list)
You are using the .remove()
function incorrectly. The remove()
function removes the element from the my_list
, it doesn’t create a new list that doesn’t have the element. Try this
my_list = ['a', 'b', 'c']
my_list.remove('c')
print(my_list)
remove()
does not return anything. Or, perhaps to be more precise, it returns None
. You’re removing 'c'
from the my_list and then setting the no_c_list to None
.
my_list = ['a', 'b', 'c']
my_list.remove('c')
print(my_list)
You are using the .remove()
function incorrectly. The remove()
function removes the element from the my_list
, it doesn’t create a new list that doesn’t have the element. Try this
my_list = ['a', 'b', 'c']
my_list.remove('c')
print(my_list)