String Methods

STEP 3 — String Methods (a.k.a. Teaching Your Text New Tricks)

STEP 3 IS HERE, and this is where strings stop being simple text and start becoming
transformers.

Not the robot kind… but honestly, just as powerful.

This step gives teens the tools to clean, format, fix, and style text so their games feel polished and professional.

Let’s unleash it.

Alright coder — you’ve created strings, you’ve combined them… Now it’s time to upgrade them.

String methods are built-in tools that let you:

  • shout in ALL CAPS
  • whisper in lowercase
  • fix messy input
  • check if something is a number or a letter
  • clean up player names
  • format dialogue
  • make your game text look GOOD

These are the “superpowers” of strings.


1. .upper() — SHOUT MODE

message = "danger ahead"
print(message.upper())

Output:
DANGER AHEAD

Perfect for boss fights.

Click Run

2. .lower() — whisper mode

name = "MARK"
print(name.lower())

Output:
mark

Useful for comparing input.

Click Run

3. .title() — Fancy Name Mode

player = "ava the brave"
print(player.title())

Output:
Ava The Brave

Your game now has style.

Click Run

4. .strip() — Clean Up Messy Input

Players type weird stuff.
Spaces everywhere.
Chaos.

name = "   Mark   "
print(name.strip())

Output:
Mark

Clean. Polished. Professional.

Click Run

5. .replace() — Swap Words Like a Magician

text = "You found a rock."
print(text.replace("rock", "potion"))

Output:
You found a potion.

Your game now edits itself.

Click Run

6. .startswith() and .endswith() — Text Detectives

command = "attack goblin"

print(command.startswith("attack"))
print(command.endswith("goblin"))

Perfect for command-based games.

Click Run

7. Why These Matter for Games

String methods let you:

  • clean player names
  • format dialogue
  • detect commands
  • build menus
  • create polished UI text
  • make your game feel intentional
  • This is where your game stops feeling “beginner” and starts feeling designed.

Mini Challenge

Take the string ” the lost sword “
Clean it, capitalize it, and print it as:

The Lost Sword

Modify and Run

Boom.
Your game now has elegant item names.
You now know how to:

  • transform text
  • clean input
  • format names
  • detect patterns
  • polish your game’s dialogue and UI
Your strings are officially leveled up.
Ready for Step 4, where we dive into string slicing — cutting, trimming, extracting, and analyzing text like a coding ninja?