CognitoCoding All posts
6 July 2026 4 min read by Eris Taylor

What Is a String in Coding? (And Why It's Just Fridge Magnets, Really)

pythonlearn-to-codestringsbeginnerscoding-concepts

You know those fridge magnets — the individual letters you rearrange to spell rude words at your mum's house?

A string is that. Your program picks up a set of characters, holds them in a line, and lets you do things with them.

That's it. That's a string.


The Short version (1 minute)

Before the deep dive — here's the concept in 60 seconds:


So what does a string actually look like in Python?

name = "Eris"
message = "Hello, welcome to Cognito Coding"
empty = ""

Those quote marks are the key. Anything inside quotes — "like this" or 'like this' — is a string. Python doesn't care whether it's words, numbers, spaces, or punctuation. If it's wrapped in quotes, it's text.

age = 14          # this is a number (integer)
age_text = "14"   # this is a string — looks the same, behaves differently

That difference matters. You can add two numbers together. You can't add a number and a string — Python will complain.


Strings remember their order

This is the fridge magnet part. Each character has a position, starting from zero.

word = "PYTHON"

print(word[0])  # P
print(word[1])  # Y
print(word[5])  # N

This is called indexing. Position 0 is the first character. Position 1 is the second. (Computers count from zero — this trips up almost everyone at first, so don't worry if it feels weird.)

You can also grab a chunk of characters in one go. This is called slicing:

word = "PYTHON"

print(word[0:3])   # PYT  (positions 0, 1, 2 — stops before 3)
print(word[2:])    # THON (position 2 all the way to the end)

Joining strings together

You can stick strings together with +. This is called concatenation (fancy word, simple idea):

first = "Cognito"
second = " Coding"

print(first + second)  # Cognito Coding

But the cleaner modern way is an f-string. Drop an f in front and use curly brackets to drop variables straight in:

player = "Eris"
score = 42

print(f"Player: {player} — Score: {score}")
# Player: Eris — Score: 42

F-strings are what you'll use in almost every real build. They're readable and they handle the joining automatically.


Useful things you can do to a string

Strings come with built-in tools. A few you'll use all the time:

text = "  hello, world!  "

print(text.upper())      # "  HELLO, WORLD!  "
print(text.lower())      # "  hello, world!  "
print(text.strip())      # "hello, world!"  (removes the spaces at either end)
print(text.replace("hello", "hi"))  # "  hi, world!  "
print(text.split(","))   # ['  hello', ' world!  ']

.split() is especially useful — it breaks a string into a list wherever it finds your chosen character. Very handy when you're reading data.


Where strings show up in real builds

Strings are everywhere. Here are three places they came up in actual Cognito Coding builds:

The Farmer Was Replaced (Episode 3 — Functions) The drone's harvest routine prints a status message after each pass. That message is a string:

def harvest_strip():
    for i in range(3):
        harvest()
        move()
    print("Strip done.")   # <-- string

The Cognitocoding Chatbot (Vibe Ep 3) Every message the user types arrives as a string. The bot reads it, processes it, and sends a string back. The entire conversation is strings flowing back and forth:

user_input = input("You: ")   # string from the keyboard
response = bot.reply(user_input)
print(f"Bot: {response}")     # string back to the screen

Lane Clash — the Roblox AI build Even in Lua (Roblox's coding language), strings show up instantly. Every label on a button, every player name, every status message is a string:

local status = "Waiting for players..."
statusLabel.Text = status

Different language, same idea: text in quotes, stored in a variable.


The one thing that catches everyone out

Adding a string and a number doesn't work:

age = 14
message = "I am " + age + " years old"   # ERROR

Python won't guess that you want to join them. You need to convert the number to a string first:

age = 14
message = "I am " + str(age) + " years old"   # works
# or, much better:
message = f"I am {age} years old"             # also works, and cleaner

Use f-strings and you mostly sidestep this entirely.


What pairs with strings next

Strings and lists go together more than you'd think. Once you know how .split() breaks a string into a list, and how to loop through a list and process each item, you start being able to handle real data — CSV files, user input, game commands.

The concept that bridges them is loops — which we covered in a previous Short and a deeper post. Then lists, which are the container that .split() hands you. Both are already on the blog if you want to keep going.


The short version (again)

A string is text, wrapped in quotes, stored in a variable. Your program can read it, change it, join it to other strings, and break it apart.

Fridge magnets. Characters in order. Yours to rearrange.

New coding concept every Monday and Thursday on the Cognito Coding YouTube channel.