定义字符串变量name,内容为:“itheima is a brand of itcast”
通过for循环,遍历此字符串,统计有多少个英文字母:“a”
提示:
- 计数可以在循环外定义一个整数类型变量用来做累加计数
- 判断是否为字母"a",可以通过if语句结合比较运算符来完成
name = 'itheima is a brand of itcast'
i = 0
for x in name:
if x == 'a':
i += 1
print(f'ithenima is a brand of itcast中共含有:{i}个字母a')