Python String Methods

In this section of the Python tutorial, we will have a look at all the built-in string functions available in Python to make the programming easy & interesting.

Method Description
lower() It converts a string into lower case
upper() It converts a string into upper case
casefold() It converts string into lower case
title() It converts the first character of each word to upper case
capitalize() It converts the first character to upper case
zfill() It fills the string with a specified number of 0 values at the beginning
format() It formats specified values in a string
format_map() It formats specified values in a string
join() It Joins the elements of an iterable to the end of the string
center() It returns a centered string
ljust() It returns a left justified version of the string
lstrip() It returns a left trim version of the string
rjust() It returns a right justified version of the string
rstrip() It returns a right trim version of the string
replace() It returns a string where a specified value is replaced with a specified value
translate() It returns a translated string
maketrans() It returns a translation table to be used in translations
strip() It returns a trimmed version of the string
partition() It returns a tuple where the string is parted into three parts
rpartition() It returns a tuple where the string is parted into three parts
encode() It returns an encoded version of the string
count() It returns the number of times a specified value occurs in a string
isalnum() It returns True if all characters in the string are alphanumeric
isdecimal() It returns True if all characters in the string are decimals
isdigit() It returns True if all characters in the string are digits
isalpha() It returns True if all characters in the string are in the alphabet
islower() It returns True if all characters in the string are lower case
isnumeric() It returns True if all characters in the string are numeric
isprintable() It returns True if all characters in the string are printable
isupper() It returns True if all characters in the string are upper case
isspace() It returns True if all characters in the string are whitespaces
endswith() It returns true if the string ends with the specified value
istitle() It returns True if the string follows the rules of a title
isidentifier() It returns True if the string is an identifier
startswith() It returns true if the string starts with the specified value
rfind() It searches the string for a specified value and returns the last position of where it was found
rindex() It searches the string for a specified value and returns the last position of where it was found
find() It searches the string for a specified value and returns the position of where it was found
index() It searches the string for a specified value and returns the position of where it was found
expandtabs() It sets the tab size of the string
splitlines() It splits the string at line breaks and returns a list
rsplit() It splits the string at the specified separator, and returns a list
split() It splits the string at the specified separator, and returns a list
swapcase() It swaps cases, lower case becomes upper case and vice versa

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart