首页 > 编程语言 > 详细

python find命令、startwith命令

时间:2015-08-02 21:32:38      阅读:238      评论:0      收藏:0      [点我收藏+]

python的字符串有很多好用的操作,比如find,startswith命令。

这几个命令在处理配置文件的时候很有用,比如用startswith判断是否是注释行。

注意:几个函数的返回值是不同滴。

函数原型:find(str, pos_start, pos_end),返回-1或第一个查找到的位置。

              startswith(str),返回false和true

              endswith(str),返回false和true

find命令:

>>> str1 = ‘hello, world‘
>>> print str1.find(‘he‘)
0
>>> print str1.find(‘wo ‘)
-1

startswith命令和endswith命令:

>>> str1 = ‘hello, world‘
>>> print str1.startswith(‘he‘)
True
>>> print str1.endswith(‘ld‘)
True

 

python find命令、startwith命令

原文:http://www.cnblogs.com/chybot/p/4696704.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!