🔗 Joining strings together
You can glue strings together with the + sign. This is called concatenation .
first = "Sky"
last = "Walker"
full = first + last
print(full) # SkyWalker
Need a space? Add one inside quotes:
full = first + " " + last
print(full) # Sky Walker
✨ f-strings — the easy way to build messages
An f-string lets you drop variables right inside text. Put an f before the quotes, and wrap variable names in { }.
name = "Maya"
age = 11
print(f"Hi {name}, you are {age} years old!")
# Hi Maya, you are 11 years old!
📌 Why f-strings rule
No more juggling + signs and quotes. f-strings are the modern, clean way to combine text and variables. You'll use them constantly!
🔢 Strings have a length
Count the characters (including spaces) with len():
word = "python"
print(len(word)) # 6
📍 Picking characters (indexing)
Each character has a position number called an index . Python starts counting at 0 !
word = "PYTHON"
# 012345
print(word[0]) # P
print(word[1]) # Y
print(word[-1]) # N (negative counts from the end)
✂️ Slicing — grabbing a piece
Take a chunk with [start:end]. The start is included, the end is not.
word = "PYTHON"
print(word[0:3]) # PYT
print(word[2:]) # THON (to the end)
print(word[:4]) # PYTH (from the start)
🛠️ Handy string methods
Strings come with built-in superpowers you call with a dot:
shout = "hello"
print(shout.upper()) # HELLO
print("LOUD".lower()) # loud
print(" hi ".strip()) # hi (removes outside spaces)
print("cat".replace("c", "b")) # bat
print("a,b,c".split(",")) # ['a', 'b', 'c']
✅ What you learned
Join strings with +, or better — use f-strings .
len() counts characters.
Indexing starts at 0 ; [-1] is the last character.
Slice with [start:end].
Methods like .upper(), .lower(), .replace() transform text.
🎮 Time to Practice!
Bend words to your will. Try the examples, then make them your own.
👋
Task 1: Personal Greeting
Easy
A variable name holds "Sam". Use an f-string to print: Hi Sam, welcome to Python!
▶ Run
✓ Check
↺ Reset
💡 Solution
name = "Sam"
print(f"Hi {name}, welcome to Python!")
🔊
Task 2: Volume Control
Medium
Print the word "shout" in UPPERCASE, the word "WHISPER" in lowercase, and the length of "programming". Output:
SHOUT
whisper
11
▶ Run
✓ Check
↺ Reset
💡 Solution
print("shout".upper())
print("WHISPER".lower())
print(len("programming"))
🍕
Task 3: Mix & Match
Tricky
Given word = "pizza" and event = "PARTY", print PIZZA party — the first word uppercased, a space, then the second word lowercased. Use an f-string and methods together!
▶ Run
✓ Check
↺ Reset
💡 Solution
word = "pizza"
event = "PARTY"
print(f"{word.upper()} {event.lower()}")
🕵️
Task 4: Free Play — Secret Initials
Creative
Store your full name in a variable. Use indexing ([0]) and slicing to print your first initial, your last character, and the first 3 letters. Experiment!