溫馨提示×

python中find函數是什么意思

摘星
6491
2021-05-31 16:49:47
欄目: 編程語言

python中find函數是實現檢索字符串并且輸出運算值的意思,語法格式為:“str.find(str, beg=0, end=len(string))”,這里“str”代表指定檢索的字符串、“beg”代表開始索引,默認為0、“end”代表結束索引,默認為字符串的長度。

python中find函數是什么意思

具體使用步驟:

1、首先打開python編輯器,新建一個python項目。

2、在python項目中定義2個字符串。

str1 = "this is string example....wow!!!";

str2 = "exam";

3、再使用find函數檢測字符串str1中是否包含子字符串str2并返回索引值。

print str1.find(str2);

返回結果:

15

相關示例代碼:

mystring = "Meet Guru99 Tutorials Site.Best site for Python Tutorials!"

print("The position of Best site is at:", mystring.find("Best site", 5, 40))

print("The position of Guru99 is at:", mystring.find("Guru99", 20))

#輸出結果

The position of Best site is at: 27

The position of Guru99 is at: -1

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女