Skip to main content
← CoursesPython FoundationsModule 3 · Functions and stringsReplace the wordwrite47 / 170
💬 Discuss🧪 Playground+75 XP
Task
📝 **Task:** `censor(text, bad_word)` replaces all occurrences with `"***"`. 📋 **Steps:** 1. `def censor(text, bad_word):` 2. `return text.replace(bad_word, "***")` 3. Call `censor("This is bad", "bad")` 💡 **Similar example (hide email):** ```python def hide_email(text): return text.replace("@", "[at]") print(hide_email("user@example.com")) # "user[at]example.com" ``` ⚠️ `.replace` replaces ALL occurrences. `"aba".replace("a", "X")` → `"XbX"`. 🎯 **Expected output:** `This is ***`

Keep going

✏️ Write your code here
🐍
Loading Python...
First visit only — ~5-10s. Stays cached afterward.
📊 Result
Press Run to see result...
📣 Help someone learn PythonShare this lesson with a friend — the first 15 are free, no signup.Tweet

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…