python中index是什麼意思
❶ python 中的index一般是什麼意思,怎麼個用法
Python index() 方法檢測字元串中是否包含子字元串 str ,如果指定 beg(開始) 和 end(結束) 范圍,則檢查是否包含在指定范圍內,該方法與 python find()方法一樣,只不過如果str不在 string中會報一個異常。
功能:從列表中找出與某個元素匹配的第一個匹配項的位置
index()方法語法:
str.index(str, beg=0, end=len(string))
str -- 指定檢索的字元串
beg -- 開始索引,默認為0。
end -- 結束索引,默認為字元串的長度。
例子:
#!/usr/bin/python
str1 = "this is string example....wow!!!";
str2 = "exam";
print str1.index(str2);
print str1.index(str2, 10);
print str1.index(str2, 40);
以上實例輸出結果如下:
15
15
Traceback (most recent call last):
File "test.py", line 8, in
print str1.index(str2, 40);
ValueError: substring not found
shell returned 1
❷ python中【index】的含義是什麼
index就是一個變數,如果前面有賦值的話,整句的意思就是如果result的第index個元素為真的話就執行冒號後面的。
index作為英語單詞,主要用作為名詞,動詞,用作名詞譯為「指標;指數;索引;指針」,用作動詞譯為「指出;編入索引中」。
index雙語例句:
1、There's even a special subject index. 甚至有一個特別的主題索引。
2、The Dow Jones index fell 15 points this morning. 道瓊斯指數今天上午下跌了15點。
3、It will be published with annotations and index. 這本書出版時將附有注釋和索引。