.strip
According to the manual, there is the method .strip()
:
minhaString.strip()
If you need to specify the characters to be removed, such as spaces only, leaving tabs and line breaks, you can use:
minhaString.strip(" ")
Note that in this second case, if you specify multiple characters, they are treated individually:
"tomate seco".strip("otm")
Return:
ate sec
.rstrip and . lstrip
If you need to remove only on the left, you have the .lstrip()
:
"banana".lstrip( "abc" )
Return:
nana
and if you need to remove only to the right, you have the .rstrip()
:
"banana".lstrip( "a" )
Return:
banan
The default of .rstrip
and of .lstrip
also is to remove spacing characters such as tabulations and line breaks.
Deprecated
For the record, this existed as a function:
string.strip( string [, caracteres] )
It worked in the same way as described above, but the string was the first argument of the call, and the second optional, the characters to be removed. Similarly, if omitted, it referred to blank spaces, tabulations and line breaks.
I am referring to myself in the past, but it will work until it is actually removed.
print "".Join(cell.Encode('utf-8').strip().Lower().split() use this function to remove the ""
– Guilherme Lima
It seems a lot of operation for a simple thing @Guilhermelima
– Wallace Maxters
why he really does so much, utf8, lowercase...
– Guilherme Lima
Is this setar utf8 thing necessary in python? It’s like PHP stuff (I have nothing against php, I love it :D)
– Wallace Maxters
@Wallacemaxters everything in Python is Unicode by default. To tell you the truth, I don’t think.
– Lucas Henrique
in reality not precise, it was a specific situation.
– Guilherme Lima