Operating environment
CentOS 6.8
Python 2.6.6
Learn how to use strip (). http://docs.python.jp/2/library/string.html
string.strip(s[, chars]) Generates and returns a copy of the string with the characters removed from the beginning and end. If chars is not specified or is set to None, leading and trailing whitespace is removed. If you specify chars other than None, chars must be a string.
http://ideone.com/5TrMOy
src = '0123456789ABCDEF'
wrk = src.strip('012')
print "1:", wrk
wrk = src.strip('79')
print "2:", wrk
wrk = src.strip('789')
print "3:", wrk
wrk = src.strip('DEF')
print "4:", wrk
result
1: 3456789ABCDEF
2: 0123456789ABCDEF
3: 0123456789ABCDEF
4: 0123456789ABC
Undigested use of chars.
Recommended Posts