发布时间:2019-09-21 11:00:14编辑:auto阅读(2091)
>>> s = 'hello good boy doiido'
>>> print s.endswith('o')
True
>>> print s.endswith('ido')
True
>>> print s.endswith('do',4)
True
>>> print s.endswith('do',4,15)
False
#匹配空字符集
>>> print s.endswith('')
True
#匹配元组
>>> print s.endswith(('t','b','o'))
True
常用环境:用于判断文件类型(比如图片,可执行文件)
>>> f = 'pic.jpg'
>>> if f.endswith(('.gif','.jpg','.png')):
print '%s is a pic' %f
else:
print '%s is not a pic' %f
pic.jpg is a pic
上一篇: MAC上打包python
下一篇: VMware Infrastructur
50993
50376
40991
37858
32323
29215
28097
22927
22896
21223
1088°
1779°
1450°
1387°
1661°
1471°
2128°
3686°
3623°
2545°