【发布时间】:2021-05-05 11:04:08
【问题描述】:
我是 python 新手,我正在寻找一个程序,要求用户填写一串字符(短语或其他),然后填写特定字符。
程序必须返回字符串中字符出现的次数。我需要使用 .count 函数,但我的代码无法正常工作。
欢迎任何帮助!
def search(text,character):
'''This function searches for one character, defined as 2nd argument,
in a given text / string of characters, defined as 1 st argument,
and counts how many times it appears'''
#The 1st argument text here represents the input in which you are looking for
text = input("Type here the text you want: ")
#The 2nd argument character represents the character you are looking for
character = input("Type the character you want to count: ")
text.count('character')
print text.count
【问题讨论】:
标签: python string input count character