字串 (string) 型態 (type) 的 index() 方法 (method) ,回傳 sub 第一次出現的索引值
方法 | 描述 |
str.index(sub[, start[, end]]) | 回傳 sub 第一次出現的索引值 |
舉例示範如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | a = "Free your mind."
b = "Welcome to the desert... of the real."
c = "What is real? How do you define real?"
d = "There is no spoon."
print (a)
print (a.index( "mind" ))
print ()
print (b)
print (b.index( "real" ))
print ()
print (c)
print (c.index( "real" ))
print ()
print (d)
print (d.index( "no" ))
print ()
|
執行結果如下
中英文術語對照 |
字串 | string |
型態 | type |
方法 | method |
內建型態
- 數字型態 int float complex 按一下展開目錄
- 迭代器型態
- 序列型態 按一下展開目錄
- 字串 str 按一下展開目錄
- str.capitalize()
- str.center(width[, fillchar])
- str.count(sub[, start[, end]])
- str.encode(encoding="utf-8", errors="strict")
- str.endswith(suffix[, start[, end]])
- str.expandtabs([tabsize])
- str.find(sub[, start[, end]])
- str.format(*args, **kwargs)
- str.index(sub[, start[, end]])
- str.isalnum()
- str.isalpha()
- str.isdecimal()
- str.isdigit()
- str.isidentifier()
- str.islower()
- str.isnumeric()
- str.isprintable()
- str.isspace()
- str.istitle()
- str.isupper()
- str.join(iterable)
- str.ljust(width[, fillchar])
- str.lower()
- str.lstrip([chars])
- static str.maketrans(x[, y[, z]])
- str.partition(sep)
- str.replace(old, new[, count])
- str.rfind(sub[, start[, end]])
- str.rindex(sub[, start[, end]])
- str.rjust(width[, fillchar])
- str.rpartition(sep)
- str.rsplit([sep[, maxsplit]])
- str.rstrip([chars])
- str.split([sep[, maxsplit]])
- str.splitlines([keepends])
- str.startswith(prefix[, start[, end]])
- str.strip([chars])
- str.swapcase()
- str.title()
- str.translate(map)
- str.upper()
- str.zfill(width)
- range
- 串列 list 按一下展開目錄
- 序對 tuple
- 字節 bytes 按一下展開目錄
- 字節陣列 bytearrary 按一下展開目錄
- 集合型態 set frozenset 按一下展開目錄
- 配對型態 dict 按一下展開目錄
沒有留言:
張貼留言