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

来源:互联网 发布:js获取选择框的值 编辑:程序博客网 时间:2024/05/18 21:06
>>> 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_IXUSR64>>> os.chmod('haha.txt',os.stat('haha.txt').st_mode | stat.S_IXUSR)

阅读全文
0 0