這是我遇到,而不是返回new_word並打印出來,它只是打印「無」當我嘗試打印出方法返回的字符串時,爲什麼我的python方法會輸出'None'?
text = "hey hey hey,hey"
word = 'hey'
def censor(text,word):
new_word = ""
count = 0
if word in text:
latter_count = ((text.index(word))+len(word))
while count < text.index(word):
new_word+= text[count]
count += 1
for i in range(len(word)):
new_word += '*'
while latter_count < len(text) :
new_word += text[latter_count]
latter_count += 1
if word in new_word :
censor(new_word,word)
else :
return new_word
print censor(text,word)