Python String Methods
Strings in Python come with a variety of methods that allow you to manipulate and analyze text data. These methods can be called on any string object.
Common String Methods
upper()
: Converts all characters in a string to uppercase.lower()
: Converts all characters in a string to lowercase.strip()
: Removes leading and trailing whitespace from a string.split()
: Splits a string into a list based on a delimiter.replace()
: Replaces occurrences of a substring with another substring.find()
: Returns the index of the first occurrence of a substring.join()
: Joins a list of strings into a single string, with a specified separator.
Example Usage
Python
# Example of using some string methods
text = " Hello, Python! "
print(text.upper()) # " HELLO, PYTHON! "
print(text.strip()) # "Hello, Python!"
print(text.replace("Python", "World")) # " Hello, World! "
Import Links
Here are some useful import links for further reading: