Censor


#1

Why doesn’t this code do anything?

def censor(text, word):
for word in text:
for i in word:
i = “*”
return text


FAQ: Learn Python - Practice Makes Perfect - censor
#2

any change made to word or i won’t persist, the for loop will simply assign the next value in string to word or i. The values assigned to this variables are copies, there is no way for this variable to make these change persist after the loop.

furthermore, looping over text will give you the the separate letters, which we can see:

def censor(text, word):
   for word in text:
      print word

censor("hey hey hey", "hey")

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.