Skip to main content

Command Palette

Search for a command to run...

Python String Methods Cheatsheet

Published
β€’2 min readβ€’View as Markdown
Python String Methods Cheatsheet
A

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

More from this blog

A

Ayesha's Tech Bytes

60 posts

Hi. Welcome to my blog! I write articles about Python, C++, UI/UX & Web Development to make your learning journey easier✨