Jun 4, 2025
a = "Harry"; a.upper() returns a new string "HARRY" without changing a.upper(): Converts all characters in a string to uppercase.lower(): Converts all characters in a string to lowercase.rstrip(): Removes trailing characters from a string.
a.rstrip("!") removes exclamation marks from the end.replace(old, new): Replaces all occurrences of a substring with another substring.
a.replace("harry", "John") replaces "harry" with "John".split(): Splits a string into a list based on a delimiter.
capitalize(): Capitalizes the first character of the string and lowers all others.center(width): Centers the string in a field of given width by padding with spaces.count(substring): Returns the number of occurrences of a substring in the string.endswith(suffix): Checks if the string ends with the specified suffix.
find(substring): Returns the index of the first occurrence of the substring. Returns -1 if not found.index(substring): Similar to find, but raises an exception if the substring is not found.isalnum(): Returns True if all characters in the string are alphanumeric.isalpha(): Returns True if all characters in the string are alphabetic.islower(): Checks if all alphabetic characters in the string are lowercase.isupper(): Checks if all alphabetic characters in the string are uppercase.isprintable(): Checks if all characters in the string are printable.isspace(): Returns True if there are only whitespace characters in the string.istitle(): Returns True if the string is titlecased (first letter of each word is uppercase).swapcase(): Swaps case of all letters in the string.title(): Converts the string to title case.