Locked lesson.
About this lesson
How to manipulate strings.
Exercise files
Download this lesson’s related exercise files.
String Manipulation.docx58.8 KB String Manipulation - Solution.docx
58.9 KB
Quick reference
String Manipulation
In this video we'll learn how to do some string manipulation.
When to use
There are always times when you'll want to manipulate strings. Here's how to do it.
Instructions
There are many ways to manipulate strings.
- .upper() = changes everything to uppercase
- .lower() = changes everything to lowercase
- .title() = changes the first letter of each word to uppercase
- .capitalize() = capitalizes just the first letter of the first word
- .swapcase() = reverses the case of every letter
To find the length of a string, wrap it in the len function:
print(len(your_variable))
Print a range of characters from a string:
print(your_variable[0:5])
Split apart your string by its spaces:
print(your_variable.split(' '))
Hints & tips
- There are many ways to manipulate strings
Lesson notes are only available for subscribers.