🐍 Python Beginner

What are Python's string methods?

Answer

Python strings have a rich set of methods (all return new strings — strings are immutable). Case: upper(), lower(), title(), capitalize(), swapcase(). Strip: strip(), lstrip(), rstrip(). Find: find(sub) (returns -1 if not found), index(sub) (raises ValueError), count(sub), startswith(prefix), endswith(suffix). Replace: replace(old, new, count). Split/Join: split(sep), rsplit(sep, maxsplit), splitlines(), join(iterable). Check: isalpha(), isdigit(), isalnum(), isspace(), islower(), isupper(). Pad: center(width), ljust(width), rjust(width), zfill(width). Encode: encode("utf-8").