I have the following list :
mylist = ["test1","test2","test3\n"]
I am trying to remove the \n
in the last element, here is how i tried :
mylist = ["test1","test2","test3\n"]
print(mylist)
> ['test1', 'test2', 'test3\n']
mylist[-1].strip("\n") # trying with .replace("\n", "") don't work too
print(mylist)
> ['test1', 'test2', 'test3\n']
I miss why it doesn't work, i can't use strip or replace on an element of a list ? Only a string ?
PS : mylist[-1]
is the right element, but as you can see, \n
is interpreted :
print(mylist[-1])
> test3
Sorry for possible duplicate, i couldn't find my error.