当前位置:   article > 正文

[PYTHON] python中startswith函数用法_python startwith

python startwith

一、当不确定python中某一函数是做什么用的可以进入函数里面分析它的源码

大致意思就是:如果prefix在S中以start开头,以end结尾,返回结果为True,否则返回False

 由上得知,其语法如下:

 S.startswith(prefix[, start[, end]])

也可以:

 S[start:end].startswith(prefix)

参数声明:

参数声明
S被检测的字符串
prefix指定的字符或子串
start设置字符串检测的起始位置(默认值为0)
end设置字符串检测的结束位置

实例:

  1. s='hello word'
  2. print s.startswith('wor')
  3. print s.startswith('h')
  4. print s.startswith('hell')
  5. print s.startswith('wor',6,9)

返回结果:
False
True
True
True

  1. s='hello word'
  2. print s[6:9].startswith('wor')
  3. print s[1:3].startswith('wor')

返回结果:

True

False

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/458861
推荐阅读
相关标签
  

闽ICP备14008679号