Python String Methods Cheatsheet

Interested in Python๐ C++๐ค UI/UX ๐ธ Web Developmentโจ
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






