word = "hello My name is Bob"
for i in word:
if i == "m":
print("There is an M")为什么不印两次,有两次?
发布于 2022-02-17 02:00:39
Python是一种区分大小写的语言,所以"M“和"m”是不同的。因此,要通过忽略大小写来比较它们,需要将两边的大小写进行转换。下面的代码将给出结果,要么是"M“,要么是"m”,例如:
word = "hello My name is Bob"
for i in word:
if i.lower() == "m".lower():
print("There is an M")https://stackoverflow.com/questions/71151541
复制相似问题