[英]Count number of character in string ( case-insensitive)
我一直在嘗試找到一種方法來使用 for 循環獲取字符串中特定字符的數量,但我無法使 function 不區分大小寫。
知道我能做什么嗎?
def main():
N = input("Please enter the string to work on:")
count = 0
find=input("Please enter a letter that youy want to find in the string entered above:")
for i in N:
if i == find:
count = count + 1
print ("The character", find, "appeared " + str( count), "times.")
main()
將調用input()
的結果小寫以忽略大小寫:
N = input("Please enter the string to work on:")
N = N.lower()
find = input("Please enter a letter that youy want to find in the string entered above:")
find = find.lower()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.