【pyhon】Python里的字符串查找函数find和java,js里的indexOf相似,找到返回序号,找不到返回-1

# 例子:
target='www.163.com'
print(target.find('163'))

if target.find('263')==-1:
    print('263不存在于字符串'+target+'')

 运行:

C:\Users\horn1\Desktop\python\7>python find.py
4
263不存在于字符串www.163.com中

 当然,如果仅仅是字符串里是否存在子串的话,使用 in 和 not in 操作符更好。

posted @ 2018-03-29 17:16  逆火狂飙  阅读(3313)  评论(0)    收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东