In python we have some very useful things called methods. Now methods are pretty much anything you use on a data type in the form dataType.method(). They are built into python and save us a lot of work and a lot of time. Python has some very useful methods that we can use on the data type string. The most commonly used and most useful ones are:
- len() * This is actually a function*
These methods are very intuitive and pretty much do exactly what they say.
.strip(): will remove any trailing or leading white spaces from a string.
.split(): will return a list of substrings from the given string. By default it splits the string by spaces (each word becomes an element in the list). However, you can choose the string to split at by inserting it between the brackets.
.lower(): will make every letter in the string lowercase.
.upper(): will make every letter in the string uppercase.
len(): will return the amount of characters in the given string (including spaces).
A practical example of when we would use these methods can be seen below: