Combining Strings

STEP 2 β€” Combining Strings (a.k.a. Making Your Game Talk Dynamically)

STEP 2 IS HERE, and this is where strings stop being quiet little text blobs and start becoming
dynamic, customizable, game-powered messages.

This is the moment your game learns how to speak with personality.

Let’s crank the energy.

Alright coder β€” in Step 1, you learned what strings are.

Now we level up.

Because a game that only prints fixed text is like a robot reading a script.

A real game needs to say things like:

  • β€œWelcome, Mark!”
  • β€œYou picked up 3 potions.”
  • β€œThe dragon dealt 12 damage!”

That means your text needs to change depending on the situation.

Enter: string combining.


1. The + Operator β€” The Classic Combo Move

You can glue strings together using +.

name = "Mark"

print("Welcome, " + name + "!")

Your game now greets players like a friendly NPC.

Click Run

2. Combining Strings + Numbers (The Gotcha)

Python won’t let you mix strings and numbers directly.

This will break (that is, you will see an error:( TypeError : can only concatenate str (not “int”) to str):

print("You have " + 5 + " coins.")

Python: β€œBro… what?”

You must convert numbers to strings:

print("You have " + str(5) + " coins.")

Boom.

Your game now counts.

Click Run

3. Using Variables Inside Messages

This is where things get fun.

player = "Ava"
item = "potion"

print(player + " picked up a " + item + "!")

Your game now reacts to what’s happening.

Click Run

4. Why This Matters for Games

Dynamic strings let you build:

  • battle messages
  • item pickups
  • shop menus
  • story narration
  • character dialogue
  • quest updates

Basically, everything your game says.


Practice (Your Turn!)

Mini-Challenge

Create a variable for a player name and a variable for an item.
Print a message like:

β€œAlex found a sword!”

Modify and Run

Your game now reacts like a narrator with style.

You now know how to:

  • combine strings
  • mix variables into messages
  • convert numbers to strings
  • create dynamic, game-powered text

Your game officially has personality.

Ready for Step 3, where we dive into string methods β€” the tools that let you transform text, shout in ALL CAPS, whisper in lowercase, and clean up messy input?