您的位置:首页 > 编程语言 > Python开发

Python高级编程-如何判断字符串a是否是以字符串b开头或结尾?

2017-11-06 21:21 1026 查看
>>> import os,stat
>>> os.listdir('.')
['DLLs', 'Doc', 'haha.txt', 'hbcdfv.py', 'helloworld.py', 'hhh.py', 'include', 'itchat.pkl', 'jksv.py', 'Lib', 'libs', 'LICENSE.txt', 'man', 'NEWS.txt', 'python.exe', 'python3.dll', 'python36.dll', 'pythonw.exe', 'render.html', 'Scripts', 'share', 'sjvjvfhvffj.py', 'tcl', 'test.txt', 'Tools', 'UI所引发的华为.py', 'vcruntime140.dll', 'xhjc.py', 'xix.py', 'xjckh.py', '京东数据爬取.py', '打印1到10.py', '是恐惧发的词.py', '机器人.py', '树2.py', '桌面 - 快捷方式.lnk', '练习.py', '词云图.py']
>>> s='haha.txt'
>>> s.endswith('.txt')
True
>>> s.endswith('.py')
False
>>> s.endswith(('.txt','.txt'))
True
>>> [ name for name in os.listdir('.') if name.endswith(('.txt','.py'))]
['haha.txt', 'hbcdfv.py', 'helloworld.py', 'hhh.py', 'jksv.py', 'LICENSE.txt', 'NEWS.txt', 'sjvjvfhvffj.py', 'test.txt', 'UI所引发的华为.py', 'xhjc.py', 'xix.py', 'xjckh.py', '京东数据爬取.py', '打印1到10.py', '是恐惧发的词.py', '机器人.py', '树2.py', '练习.py', '词云图.py']
>>> os.stat('haha.txt')
os.stat_result(st_mode=33206, st_ino=56013520365422465, st_dev=3357566155, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1507602672, st_mtime=1507602672, st_ctime=1507602672)
>>> oct(os.stat('haha.txt').st_mode)
'0o100666'
>>> stat.S_IXUSR
64
>>> os.chmod('haha.txt',os.stat('haha.txt').st_mode | stat.S_IXUSR)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐