remove the last character or the newline character?

Daniel Mark danielmarkhot at gmail.com
Thu Sep 28 16:14:43 CEST 2006


Hello all:

I have the following snippet:

In [1]: fileName = 'Perfect Setup.txt\n'
In [2]: fileName = fileName[0:len(fileName)-1)]   # remove the '\n'
character
In [3]: fileName
Out[3]: 'Perfect Setup.txt'

Question one:
Does python provide any function that can remove the last character of
a string?
I don't know whether or not the method I used is efficient

Question two:
Does python provide any function that can remove the newline character
from a string if it exists?



Thank very much!
-Daniel




More information about the Python-list mailing list