Re: remove the last character or the newline character?
- From: John Salerno <johnjsal@xxxxxxxxxxxxxxx>
- Date: Thu, 28 Sep 2006 14:22:30 GMT
Daniel Mark wrote:
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
Doing fileName[-1] lets you access the last character, but I'm not sure about removing it since strings are immutable. It would still probably be something like you did.
Question two:
Does python provide any function that can remove the newline character
from a string if it exists?
>>> fileName = 'Perfect Setup.txt\n'
>>> fileName.strip()
'Perfect Setup.txt'
>>>
Or you can use lstrip() or rstrip() to remove just the left or right side.
.
- Follow-Ups:
- Re: remove the last character or the newline character?
- From: Tim Chase
- Re: remove the last character or the newline character?
- References:
- remove the last character or the newline character?
- From: Daniel Mark
- remove the last character or the newline character?
- Prev by Date: Re: Questions on Using Python to Teach Data Structures and Algorithms
- Next by Date: Re: remove the last character or the newline character?
- Previous by thread: remove the last character or the newline character?
- Next by thread: Re: remove the last character or the newline character?
- Index(es):
Relevant Pages
|