Strip Characters From a Python String

Joseph Peart
Joseph Peart 8 Lessons 27m basics python

By default, Python’s .strip() method removes whitespace characters from both ends of a string. To remove different characters, you can pass a string as an argument that specifies a set of characters to remove. The .strip() method is useful for tasks like cleaning user input, standardizing filenames, and preparing data for storage.

By the end of this video course, you’ll understand that:

  • The .strip() method removes leading and trailing whitespace but doesn’t remove whitespace from the middle of a string.
  • You can use .strip() to remove specified characters from both ends of the string by providing these characters as an argument.
  • With the related methods .lstrip() and .rstrip(), you can remove characters from one side of the string only.
  • All three methods, .strip(), .lstrip(), and .rstrip(), remove character sets, not sequences.
  • You can use .removeprefix() and .removesuffix() to strip character sequences from the start or end of a string.

What’s Included:

  • 8 Lessons
  • Video Subtitles and Full Transcripts
  • 2 Downloadable Resources
  • Accompanying Text-Based Tutorial
  • Interactive Quiz to Check Your Progress
  • Q&A With Python Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

Related Learning Paths:

About Joseph Peart

Joseph is a software developer, data geek, bootcamp instructor, and board game enthusiast. He lives in Canada with his wife and cats. He loves learning new things, teaching those things to other people, and talking about himself in the third person.

» More about Joseph

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

← Browse All Courses