Strings Built-In Methods
In this post I want to show what you can do with the built-in methods for python Strings. Let’s first create a string with the value of “Hello World”
string = "Hello World"
To manipulate strings, we can use some of Pythons built-in methods
string.upper() # get all-letters in uppercase
string.lower() # get all-letters in lowercase
string.capitalize() # capitalize the first letter
string.title() # capitalize the first letter of words
string.swapcase() # converts uppercase and lowercase
string.strip() # remove all white spaces
string.lstrip() # removes white space from left
string.rstrip() # removes white space from right
string.split() # splitting words
string.split(',') # split words by comma
string.count('l') # count how many times l is in the string
string.find('Wo') # find the word Wo in the string
string.index("Wo") # find the letters Wo in the string
":".join(string) # add a : between every char
" ".join(string) # add a white space between every char
len(string) # find the length of the string
Recommended Python Training
Course: Python 3 For Beginners
Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.