Skip to content
dreamcode
dreamcode
Map
String methods
Lesson 5 of 77
+15 XP on finish
PYTHON BASICSChapter 1 · Python Basics

String methods

Strings come with methods: small built-in tools you call with a dot. .upper() and .lower() change case, .strip() trims spaces from both ends, .replace(a, b) swaps text, .split() breaks a string into a list of words, and in checks whether one piece of text is inside another. Methods return a new string. The original never changes.

Worked example

How it reads

  • .strip() removes the spaces at both ends
  • .split() with no argument splits on spaces and returns a list
  • Strings never change in place, so save or print the result
Common mistakes
  • Calling name.upper() without saving or printing the result. Strings never change in place.
  • Writing name.upper without parentheses gives you the method itself, not the result.
Cloud tip: Chain methods left to right: raw.strip().lower() trims first, then lowercases.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Print the title trimmed and in capital letters, exactly THE NIGHT SKY.

Press Run to check your work.