Python startswith endswith

如果你要用python匹配字符串的开头或末尾是否包含一个字符串,就可以用startswith,和endswith

比如:content = ‘test.png’

如果字符串content以test开始,返回True,否则返回False

content.startswith(“test”)

返回true

content.startswith(“sss”)

返回false

如果字符串content以.png结尾,返回True,否则返回False
content.endswith(‘.png’)

返回true

content.endswith(“.jpg”)

返回false

 

http://www.waitingfy.com/archives/1853

1853

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.