python字符串find

String.find()方法 (String.find() Method)

find() is an inbuilt method of python, it is used to check whether a sub-string exists in the string or not. If sub-string exists, the method returns the lowest index of the sub-string, if sub-string does not exist, method return -1.

find()是python的内置方法,用于检查字符串中是否存在子字符串。 如果存在子字符串,则该方法返回子字符串的最低索引,如果子字符串不存在,则方法返回-1。

Note: This method is case sensitive.

注意:此方法区分大小写。

Syntax:

句法:

 String.find(sub_string[, start_index[, end_index]])

Parameters:

参数:

  • sub_string - a part of the string to be found in the string.

    sub_string-要在字符串中找到的字符串的一部分。

  • start_index - an optional parameter, it defines the starting index from where sub_string should be found.

    start_index-可选参数,它定义从中应找到sub_string的起始索引。

  • end_index - an optional parameter, it defines end index of the string. Find method will find the sub_string till this end_index.

    end_index-可选参数,它定义字符串的结束索引。 Find方法将查找sub_string直到此end_index 。

Return value:

返回值:

  • Returns the lowest index of the sub_string, if it exits in the string.

    返回 sub_string 的最低索引 ,如果它存在于字符串中。

  • Returns -1 if sub_string does not exist in the string.

    如果sub_string在字符串中不存在,则返回-1

Example:

例:

# string in which we have to find the sub_string
str = "Hello world, how are you?"
# sub_string to find the given string
sub_str = "how"
# find by sub_str
print (str.find (sub_str))
# find by sub_str with slice:start index
print (str.find (sub_str, 10))
# find by sub_str with slice:start index and slice: end index
print (str.find (sub_str, 10, 24))
# find a sub_str that does not exist
sub_str = "friend"
# find by sub_str
print (str.find (sub_str))
# find a sub_str with different case
sub_str = "HOW"
# find by sub_str
print (str.find (sub_str))

Output

输出量

    13
13
13
-1
-1

翻译自: https://www.includehelp.com/python/string-find-method-with-example.aspx

python字符串find

python字符串find_Python字符串| 带示例的find()方法相关推荐

  1. python字符串find_Python字符串find()

    python字符串find Python String find() method is used to find the index of a substring in a string. Pyth ...

  2. python requests返回结果带\\u的解决方法

    request请求里结果带\u的解决方法 形如 "\\u80a1\\u7968\\u4ee3\\u7801" 解决方法 result = result.content.decode ...

  3. python 字符串 find_Python 字符串 find() 方法

    例如: 字符串中"welcome"的位置索引:txt = "Hello, welcome to my world." x = txt.find("we ...

  4. python字符串startswith_Python 字符串 startswith() 使用方法及示例

    Python 字符串 startswith() 使用方法及示例 如果字符串以指定的前缀(字符串)开头,则startswith()方法将返回True.如果不是,则返回False. startswith( ...

  5. Python正则替换字符串函数re.sub用法示例(1)

    本文实例讲述了Python正则替换字符串函数re.sub用法.分享给大家供大家参考,具体如下: python re.sub属于python正则的标准库,主要是的功能是用正则匹配要替换的字符串 然后把它 ...

  6. python实现加密字符串_Python实现对字符串的加密解密方法示例

    本文实例讲述了Python实现对字符串的加密解密方法.分享给大家供大家参考,具体如下: 需求是是要将密码存在数据库里,所以要加密解密是可逆的,在数据库里不要有特殊字符,防止数据库备份和恢复中出错. 安 ...

  7. python如何加密字符串_Python实现对字符串的加密解密方法示例

    本文实例讲述了Python实现对字符串的加密解密方法.分享给大家供大家参考,具体如下: 需求是是要将密码存在数据库里,所以要加密解密是可逆的,在数据库里不要有特殊字符,防止数据库备份和恢复中出错. 安 ...

  8. Java字符串indexOf(int ch,int fromIndex)方法,带示例

    字符串indexOf(int ch,int fromIndex)方法 (String indexOf(int ch, int fromIndex) Method) indexOf(int ch, in ...

  9. python如何判断字符串长度_Python如何查找字符串的长度?(代码示例)

    在Python中字符串是Unicode代码点的不可变序列.给定一个字符串,我们如何查找它的长度?本篇文章就来给大家介绍在Python中查找字符串长度的四种方法,希望对大家有所帮助.[相关视频教程推荐: ...

最新文章

  1. jmeter测试webservice接口
  2. 作业6 分析项目的NABCD和项目的产品Backlog
  3. DB2中导出数据库的所有DDL脚本
  4. Nginx的启动和停止
  5. 在MFC单文档中,如何操作状态栏
  6. 線陣相機處理時間計算方法
  7. 前端学习(2585):前端怎么在响应头和请求头里面拿数据?
  8. wpf的listbox循环数据滚动_滚动版 CentOS Stream 和 Fedora 的关系
  9. Java List retainAll 记录坑
  10. note2便携式WLAN热点开启后没连接时自动关闭时长在哪设置
  11. 解决win10新装系统无法登录微软账户及microsoft store
  12. TensorFlow学习(11)——卷积神经网络
  13. zookeeper(五)集群角色epoch的选取
  14. JS+CSS实现页面滚动切换图片(从边角扩散)的效果
  15. Docker教程(Docker实战)
  16. 一个简单的马赛克例子
  17. 天龙八部修改服务器经验,端游【天龙八部万象归一服务端】万象量一第7版一键端架设客户端+详细修改教程...
  18. ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
  19. php薄饼,即将消失的汕头美食:糖葱薄饼
  20. 论文阅读:《Bag of Tricks for Long-Tailed Visual Recognition with Deep Convolutional Neural Networks》

热门文章

  1. 计算机护理职称考试报名时间2015,护理职称考试怎么报名?
  2. java char i=2+#039;2#039;;_P039 二维数组的字符按列存放到字符串中 ★★
  3. 【SSM面向CRUD编程专栏 1】Spring简介 xml配置文件 依赖注入 数据注入
  4. Java集合:Collection接口
  5. 为什么MIP-Cache存在
  6. Sublime Text 3 无法输入中文解决方案
  7. 10 种保护 Spring Boot 应用的绝佳方法 1
  8. python练习笔记——利用信号signal处理僵尸进程
  9. 使用IHttpHandler做权限控制[ASP.NET | IHttpHandler | AjaxPro | UserHostName]
  10. debian8.8安装谷歌浏览器