Python has a set of built-in methods that you can use on strings.
Upper Case
Example
a = "Hello, World!"
print(a.upper())
Lower Case
Example
a = "Hello, World!"
print(a.lower())
Remove Whitespace
Whitespace is the space before and/or after the actual text, and very often you want to remove this space.
Example
a = " Hello, World! "
print(a.strip()) # returns "Hello, World!"
Replace String
Example
a = "Hello, World!"
print(a.replace("H", "J"))
Split String
The split() method returns a list where the text between the specified separator becomes the list items.
Example
a = "Hello, World!"
print(a.split(",")) #
returns ['Hello', ' World!']
Learn more about Lists in our Python Lists chapter.
String Methods
Learn more about String Methods with our String Methods Reference