- Get link
- X
- Other Apps
In Python, strings are like text containers that come with their own set of useful tools. These tools, called string methods, allow you to modify and work with strings in different ways. Here are some commonly used string methods and what they do: 1. ` capitalize() `: Makes the first letter of a string uppercase and the rest lowercase. 2. ` casefold() `: Converts the entire string to lowercase, even handling special cases. 3. ` center(width[, fillchar]) `: Puts a string in the middle of a line of a specific width, optionally filling the extra space with a chosen character. 4. ` count(sub[, start[, end]]) `: Counts how many times a specific part of a string appears within it. 5. ` endswith(suffix[, start[, end]]) `: Checks if a string ends with a particular set of characters and returns True or False. 6. ` find(sub[, start[, end]]) `: Searches for a specific part of a string and tells you where it starts. If not found, it returns -1. 7. ` index(sub[, start[, end]]) `: Similar to `find()...