Python String Methods Cheatsheet

Python String Methods Cheatsheet

What are strings?

✨ In computer science, sequences of characters are called strings.

✨ They can be of any length.

✨ They can include any character such as letters, numbers, symbols or whitespace(spaces, tabs, new lines).

Below is a list of Python string methods ;)

String Methods

👉 capitalize(): Converts first character to uppercase.

👉 casefold(): converts string into lowercase.

👉 center(): returns a centered string.

👉 count(): returns the number of times a specified value occured in a string.

👉 encode(): returns an encoded string

👉 endswith(): returns true if string ended with the specified value.

👉 expandtabs(): sets tab size of the string.

👉 find() and index(): searches string for a specified value and returns the position of where the value was found.

👉 isascii(): returns true if all characters of a string are ascii characters.

👉 isdecimal(): returns true of all characters of a string are decimals.

👉 isdigit(): returns true if all characters in a string are digits.

👉 format() and format_map(): format specified value in a string.

👉 isalnum(): Returns true if all characters of a string are alphanumeric.

👉 isalpha(): Returns true if all characters of a string are in the alphabet.

👉 isnumeric(): returns true if all characters in a string are numeric.

👉 isprintable(): returns true if all characters in a string are printable.

👉 islower(): returns true if all characters of string are lower case.

👉 isupper(): returns true if all characters of string are upper case.

👉 join(): joins the elements of an iterable to end of a string.

👉 lower(): converts string in lower case.

👉 upper(): converts string in upper case.

👉partition(): return a tuple where string is parted in 3 portions.

👉 split(): splits the string at the specified separated and the returns a list.

👉 splitlines(): split string at line breaks and then returns a list.

👉 strip(): returns a trimmed version of a string.

👉 swapcase(): swaps cases, upper case becomes lower case and vice versa.

👉 title(): converts the first character of each word of a string to upper case.

👉 zfill(): fills string with specified number of 0 values at the beginning

👉 replace(): returns a string where the specified value is replaced with a specified value.

👉 isidentifier(): returns true if a string is an identifier.

Let's connect!

Twitter

Github