TQC+ 程式語言 Python 3 _ 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
程式碼:
str1 = input()

for i in range(len(str1)): print('Index of \'{}\': {}'.format(str1[i],i))

沒有留言:

張貼留言