String Methods

Python has a set of built-in methods that you can use on strings.

Example

The strip() method removes any whitespace from the beginning or the end:

a = " Hello, World! "

print(a.strip()) # returns "Hello, World!"

Example

The lower() method returns the string in lower case:

a = "Hello, World!"

print(a.lower())

Example

The upper() method returns the string in upper case:

a = "Hello, World!"

print(a.upper())

Example

The replace() method replaces a string with another string:

a = "Hello, World!"

print(a.replace("H", "J"))

Example

The split() method splits the string into substrings if it finds instances of the separator:

a = "Hello, World!"

print(a.split(",")) # returns ['Hello', ' World!']

Jay Kakadiya

Jay Kakadiya Creator

I am a computer field, & i am Web developer.

Suggested Creators

Jay Kakadiya