第8類:字串(String)的運作

TQC+ 程式語言Python 801 字串索引

題目說明:

請撰寫一程式,要求使用者輸入一字串,顯示該字串每個字元的索引。

範例輸入

Sandwich

範例輸出

Index of 'S': 0
Index of 'a': 1
Index of 'n': 2
Index of 'd': 3
Index of 'w': 4
Index of 'i': 5
Index of 'c': 6
Index of 'h': 7
 

程式碼:

Str = input()

for i in range(len(Str)):
    print("Index of '%s': %d" %(Str[i], i))

 

TQC+ 程式語言Python 第8類:字串(String)的運作





如果覺得文章內容還不錯的話,麻煩請幫我點個讚!感謝

可以多點幾次喔~~

第一次點讚需使用 Google 或 Facebook 帳號註冊

一個評論

發表迴響