Python Academy · Lesson

Common String Methods

Explore upper, lower, strip, split, replace, and find methods.

Lesson 3 of 414 steps

Common String Methods is a free Python Academy lesson on CoddyKit. This is lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, and your progress syncs across the web and the CoddyKit app. The Python Academy course includes 4 lessons in total.

Introduction

Python strings have dozens of built-in methods for searching, transforming, and validating text.

upper() and lower()

'hello'.upper() gives 'HELLO'. 'WORLD'.lower() gives 'world'. Neither modifies the original — they return new strings.
print('hello'.upper())
print('WORLD'.lower())

strip(), lstrip(), rstrip()

' hi '.strip() removes whitespace from both ends. lstrip() removes from the left, rstrip() from the right.
s = '  hello  '
print(s.strip())

split() and splitlines()

'a,b,c'.split(',') gives ['a','b','c']. split() with no args splits on any whitespace and removes empty strings.
print('a,b,c'.split(','))
print('hi there'.split())

replace()

'hello world'.replace('world', 'Python') gives 'hello Python'. Optional count argument limits replacements.
s = 'aabbaa'
print(s.replace('aa', 'XX'))

find() and index()

find() returns the index of the first match, or -1 if not found. index() raises ValueError when not found.
s = 'hello world'
print(s.find('world'))
print(s.find('xyz'))

startswith() and endswith()

s.startswith('Py') returns True if s begins with 'Py'. Both accept a tuple of prefixes/suffixes.
print('Python'.startswith('Py'))
print('test.py'.endswith('.py'))

count()

'banana'.count('a') returns 3 — the number of non-overlapping occurrences of the substring.
print('banana'.count('a'))

isdigit(), isalpha(), isalnum()

Validation helpers: '123'.isdigit() is True. 'abc'.isalpha() is True. 'abc123'.isalnum() is True.
print('123'.isdigit())
print('abc'.isalpha())

title() and capitalize()

'hello world'.title() gives 'Hello World'. 'hello'.capitalize() gives 'Hello' (only first char).
print('hello world'.title())
print('hello'.capitalize())

center(), ljust(), rjust()

'hi'.center(10) gives ' hi '. Use a fill character: 'hi'.center(10, '-') gives '----hi----'.
print('hi'.center(10, '-'))

Quick Check

Which method returns -1 when a substring is not found?

Recap

Key string methods: upper/lower, strip, split, replace, find/index, startswith/endswith, count, isdigit/isalpha, title/capitalize, center/ljust/rjust.

Keep Going

Great work! Move on to the next lesson to continue building your skills.
Free to start

Learn Python with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
76
Lessons
320

Frequently Asked Questions

Is the “Common String Methods” lesson free?

Yes — the full text of “Common String Methods” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO. The Python Academy course includes 4 lessons in total.

What will I learn in “Common String Methods”?

Explore upper, lower, strip, split, replace, and find methods. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Python Academy?

No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Common String Methods” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Python Academy lesson?

Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. String Basics and Indexing
  2. String Slicing and Concatenation
  3. Common String Methods
  4. String Formatting with f-strings
← Back to Python Academy