日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python字符串find_Python字符串| 带示例的find()方法

發(fā)布時間:2025/3/11 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python字符串find_Python字符串| 带示例的find()方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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的內(nèi)置方法,用于檢查字符串中是否存在子字符串。 如果存在子字符串,則該方法返回子字符串的最低索引,如果子字符串不存在,則方法返回-1。

Note: This method is case sensitive.

注意:此方法區(qū)分大小寫。

Syntax:

句法:

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

Parameters:

參數(shù):

  • 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-可選參數(shù),它定義從中應找到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-可選參數(shù),它定義字符串的結束索引。 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

輸出量

131313-1-1

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

python字符串find

總結

以上是生活随笔為你收集整理的python字符串find_Python字符串| 带示例的find()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。