Strings - Practice Exercise
Python String Operations Cheat Sheet
str.capitalize()
- Capitalize first letterstr.title()
- Capitalize first letter of each wordstr.upper()
- All uppercasestr.lower()
- All lowercasestr.strip()
- Remove whitespacestr.lstrip()
,str.rstrip()
- Remove left/right whitespacestr.replace(old, new)
- Replace substringstr.split(sep)
- Split into liststr.join(list)
- Join list into stringstr.find(sub)
- Find substring indexstr.startswith(prefix)
,str.endswith(suffix)
str.isdigit()
,str.isalpha()
,str.isalnum()
str.format(...)
- Format stringf"...{var}..."
- f-string formattingstr[begin:end]
- Slicing