Python String Methods: str(), upper(), lower(), count(), find(), replace() & len()

Python String Methods: str(), upper(), lower(), count(), find(), replace() & len()

There are several built-in methods that allow us to easily make modifications to strings in Python. In this tutorial we will cover the .upper(), .lower(), .count(), .find(), .replace() and str() methods.

But first, let’s take a look at the len() method. While it’s not limited to strings, now is a good time to make the introduction. We use the built-in Python method, len(), to get the length of any sequence, ordered or unordered: strings, lists, tuples, and dictionaries. For example:

String Methods

.upper() & .lower()

The .upper() and .lower() string methods are self-explanatory. Performing the .upper() method on a string converts all of the characters to uppercase, whereas the lower() method converts all of the characters to lowercase.


The .count() method adds up the number of times a character or sequence of characters appears in a string. For example:

Why didn’t it count all of the t‘s? Because ‘T’ is a different character from ‘t’. So, if we want to count all of the t‘s.

We can also count entire words, which, as we know, are sequences of characters:


We search for a specific character or characters in a string with the .find() method.

The results tell us that “hand” begins at the 13th position in the sequence.

But if we want to find the second “o” we need to specify a range.

This begins searching at the 8th element and finds “o” at 20. You can also specificy an end to the range, and, like slicing, we can do so backwards:


Let’s say we want to increase the value of a statement. We do so with the .replace() method. For example:

String Conversion

How does one become one with everything? With the str() method.

Now that you are enlightened, you can stop learning Python and live in the moment. OR: You can learn about lists in our next chapter.

Python String Methods: str(), upper(), lower(), count(), find(), replace() & len() was posted by on . Jared likes to make things. He really wants you to watch The Hello World Program so you can learn the skills you need to build an awesome future. His contributions to the show include puppetry, 3D animation, doodling and speaking in a bad British accent. And yes, that is a fox sitting on his face.

Discuss this article in the Comments below, or and it with your friends. Learn more about Python by subscribing to The Hello World Newsletter .

Join the Discussion
  • Bill Cunningham

    What you probably should have mentioned was that Strings in Python are immutable and therefore these operations act on but do not alter the string itself. This can be distressing to the new Python programmer that might have been expecting that the string was altered in place. You do an s = s.lower() but do not explain why.

  • diymanik

    Great job with this tutorial. I’m going to share it on my website

  • Awesome, thanks!

  • Petey2099

    Im just learning all of this stuff, the last month has been a wreck trying to figure out what things mean. Dude you made just these 7 methods the easiest to understand compared to any of the others.

  • Kevin T

    Hi, i was working through this tutorial (It’s fantastic btw!) i noticed that in a few of the examples i see a diamond with a question mark in it. I then noticed i could change it to “plain” text and then the correct letters and quotes would come in. Is there anyway to fix this without changing all the examples to plain text? I’m using the latest google chrome Version 43.0.2357.81 m. Thanks!

  • Thanks for catching that. It was caused by errant Unicode quotation marks. Made the changes.

Subscribe to our Mailing List

Stay up to date on the latest videos and tutorials with our monthly newsletter

The email entered is invalid