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?