computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

🦸

🎓

⏱ 25 min

Free

String Superpowers

Slice, search and style text with string methods and f-strings.

🎯 What you will learn

  • Use f-strings to build messages
  • Use methods like upper(), lower() and replace()
  • Slice and search strings

👋 Let’s get started!

Text is everywhere in apps: usernames, messages, passwords. Python gives strings amazing superpowers 🦸 — let’s unlock them.

🪜 Step by step

1. ✨ f-strings

Put f before the quotes and variables in { } — no more + juggling!

name = "Leo"
level = 4
print(f"{name} reached level {level}! 🎮")
2. 🧰 Methods

Methods are functions that belong to a value. Use a dot!

word = "Python"
print(word.upper())
print(word.lower())
print(word.replace("P", "J"))
3. ✂️ Slicing & searching

Grab parts with [start:end] and search with in.

msg = "Hello world"
print(msg[0:5])
print("world" in msg)

🧪 Try it!

Change the code and press ▶ Run to see what happens. You can’t break anything!

Username maker

first = "maya"
animal = "otter"
number = 42
username = f"{first.capitalize()}{animal.capitalize()}{number}"
print("Your username:", username)
print("Length:", len(username))

Shout a greeting

name = input("Name? ")
loud = name.upper()
print(f"HELLO {loud}!!!")

📖 Key words

Tap a card to flip it over!

f-string
A string with {variables} inside ✨
Method
A function attached with a dot 🔧
Slice
Part of a string [start:end] ✂️

🏆 Challenge

Use an f-string to print: Kim has 3 badges

Challenge

player = "Kim"
badges = 3

Knowledge Check Quiz

  1. What prints?
  2. What prints?
  3. What prints?
← Previous lesson
Next lesson →