Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strip in Python

Tags:

python

strip

I have a question regarding strip() in Python. I am trying to strip a semi-colon from a string, I know how to do this when the semi-colon is at the end of the string, but how would I do it if it is not the last element, but say the second to last element.

eg:

1;2;3;4;\n

I would like to strip that last semi-colon.

like image 269
crappy smith Avatar asked Nov 30 '22 02:11

crappy smith


1 Answers

Strip the other characters as well.

>>> '1;2;3;4;\n'.strip('\n;')
'1;2;3;4'
like image 106
Ignacio Vazquez-Abrams Avatar answered Dec 05 '22 12:12

Ignacio Vazquez-Abrams