Monday, July 29, 2019

python - Remove the first character of a string

Your problem seems unclear. You say you want to remove "a character from a certain position" then go on to say you want to remove a particular character.



If you only need to remove the first character you would do:




s = ":dfa:sif:e"
fixed = s[1:]


If you want to remove a character at a particular position, you would do:



s = ":dfa:sif:e"
fixed = s[0:pos]+s[pos+1:]



If you need to remove a particular character, say ':', the first time it is encountered in a string then you would do:



s = ":dfa:sif:e"
fixed = ''.join(s.split(':', 1))

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...