Skip to main content

Command Palette

Search for a command to run...

Python String Methods Cheatsheet

Published
โ€ข2 min read
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โœจ