String manipulation is an important part of many programming tasks, including data analysis and text processing. Python provides several built-in methods and functions for manipulating strings. Here are some of the most commonly used ones:
len(string): Returns the length of a string.
string.upper(): Converts all characters in a string to uppercase.
string.lower(): Converts all characters in a string to lowercase.
string.capitalize(): Converts the first character of a string to uppercase and the rest to lowercase.
string.title(): Converts the first character of each word in a string to uppercase and the rest to lowercase.
string.strip(): Removes any whitespace characters from the beginning and end of a string.
string.split(separator): Splits a string into a list of substrings at the specified separator character.
string.join(iterable): Joins the elements of an iterable (such as a list or tuple) into a single string using the specified string as a separator.
string.replace(old, new): Replaces all occurrences of a substring in a string with a new substring.
string.startswith(prefix): Returns a boolean indicating whether a string starts with a specified prefix.
string.endswith(suffix): Returns a boolean indicating whether a string ends with a specified suffix.
string.find(substring): Returns the index of the first occurrence of a substring in a string, or -1 if the substring is not found.
string.count(substring): Returns the number of occurrences of a substring in a string.
string.format(args): Formats a string with the specified arguments.
These are just some of the most commonly used string manipulation methods in Python. There are many more, and you can find more information on them in the Python documentation.