# 统计如下字符串中,有多少个字母a name = "I am a happy person and I enjoy eating apples" # 定义一个变量,用来统计有多少个a count = 0 # for 循环统计 # for 临时变量 in 被统计的数据: for x in name: if x == "a": count += 1 print(f"{name}中共有{count}个a")