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

>>> 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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值