Case Conversion:
.upper(): Converts a string to uppercase.
.lower(): Converts a string to lowercase.
.capitalize(): Capitalizes the first character of a string.
.swapcase(): Swaps the case of all characters in a string.
Whitespace Manipulation:
.strip(): Removes leading and trailing whitespace from a string.
.lstrip(): Removes leading whitespace from a string.
.rstrip(): Removes trailing whitespace from a string.
String Searching:
.find(substring): Returns the index of the first occurrence of a substring.
.startswith(substring): Checks if a string starts with a substring.
.endswith(substring): Checks if a string ends with a substring.
String Manipulation:
.replace(old, new): Replaces all occurrences of a substring with another.
.split(delimiter): Splits a string into a list of substrings based on a delimiter.
.join(iterable): Concatenates elements of an iterable into a single string.
String Testing:
.isalpha(): Checks if all characters are alphabetic.
.isdigit(): Checks if all characters are digits.
.isspace(): Checks if all characters are whitespace.
Other Useful Functions:
len(string): Returns the length of the string.
String slicing string[start:end] extracts a substring from a string.
String concatenation string1 + string2 combines two strings.
Formatted string literals (f-strings) f"Hello, {name}!" provide a way to embed expressions inside string literals.
Created
June 5, 2025 01:14
-
-
Save avidrucker/86dedf1fa3ecd910ca24d2e56512a860 to your computer and use it in GitHub Desktop.
Python string functions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment