(1) 逐一取出字串內容
1. 使用for...in...取出字串中的每個字
#設定初值
data = 'In many systems, scalability becomes the primary driver as the user base grows.'
cnt = 0
#逐一取出字串內容
for d in data:
#判斷是否為a
if d=='a':
cnt+=1
#印出結果
print(f'共有{cnt}個a')共有6個a
2. 用索引值取出字串中的每個字

自主練習
Last updated