[GO] python> Example of using strip ()> src = '0123456789ABCDEF' / wrk = src.strip ('DEF')

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

python> Example of using strip ()> src = '0123456789ABCDEF' / wrk = src.strip ('DEF')
Example of using lambda
python: Basics of using scikit-learn ①
Image capture of firefox using python
Removal of haze using Python detailEnhanceFilter
Implementation of desktop notifications using Python
Python: Basics of image recognition using CNN
[Python] Extension using inheritance of matplotlib (NavigationToolbar2TK)
Execution example of blob detection using OpenCV
About building GUI using TKinter of Python
(Bad) practice of using this in Python
Example of using class variables and class methods
Python: Application of image recognition using CNN
Example of 3D skeleton analysis by Python
Study on Tokyo Rent Using Python (3-1 of 3)
Practical example of Hexagonal Architecture in Python
Meaning of using DI framework in Python