We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5
Strings
A String is a data structure in Python that represents a sequence of
characters. It is an immutable data type, meaning that once you have created a string, you cannot change it.
Method Description Syntax
capitalize() Converts the first character to string.capitalize()
upper case
casefold() Converts string into lower case string.casefold()
center() Returns a centered string string.center(length,charact
er)
count() Returns the number of times a string.count(value, start,
specified value occurs in a string end)
encode() Returns an encoded version of string.encode(encoding=enc
the string oding, errors=errors)
endswith() Returns true if the string ends string.endswith(value, start,
with the specified value end)
expandtabs( Sets the tab size of the string string.expandtabs(tabsize)
)
find() Searches the string for a string.find(value, start, end)
specified value and returns the position of where it was found
format() Formats specified values in a string.format(value1,
string value2...) format_map Formats specified values in a () string
index() Searches the string for a string.index(value, start,
specified value and returns the end) position of where it was found
isalnum() Returns True if all characters in string.isalnum()
the string are alphanumeric
isalpha() Returns True if all characters in string.isalpha()
the string are in the alphabet
isascii() Returns True if all characters in string.isascii()
the string are ascii characters
isdecimal() Returns True if all characters in string.isdecimal()
the string are decimals
isdigit() Returns True if all characters in string.isdigit()
the string are digits
isidentifier( Returns True if the string is an string.isidentifier()
) identifier
islower() Returns True if all characters in string.islower()
the string are lower case
isnumeric() Returns True if all characters in string.isnumeric()
the string are numeric
isprintable() Returns True if all characters in string.isprintable()
the string are printable isspace() Returns True if all characters in string.isspace() the string are whitespaces
istitle() Returns True if the string follows string.istitle()
the rules of a title
isupper() Returns True if all characters in string.isupper()
the string are upper case
join() Converts the elements of an string.join(iterable)
iterable into a string
ljust() Returns a left justified version of string.ljust(length,
the string character)
lower() Converts a string into lower case string.lower()
lstrip() Returns a left trim version of the string.lstrip(characters)
string
maketrans() Returns a translation table to be str.maketrans(x, y, z)
used in translations
partition() Returns a tuple where the string string.partition(value)
is parted into three parts
replace() Returns a string where a string.replace(oldvalue,
specified value is replaced with a newvalue, count) specified value
rfind() Searches the string for a string.rfind(value, start,
specified value and returns the end) last position of where it was found rindex() Searches the string for a string.rindex(value, start, specified value and returns the end) last position of where it was found
rjust() Returns a right justified version string.rjust(length,
of the string character)
rpartition() Returns a tuple where the string string.rpartition(value)
is parted into three parts
rsplit() Splits the string at the specified string.rsplit(separator,
separator, and returns a list maxsplit)
rstrip() Returns a right trim version of string.rstrip(characters)
the string
split() Splits the string at the specified string.split(separator,
separator, and returns a list maxsplit)
splitlines() Splits the string at line breaks string.splitlines(keeplinebre
and returns a list aks)
startswith() Returns true if the string starts string.startswith(value,
with the specified value start, end)
strip() Returns a trimmed version of the string.strip(characters)
string
swapcase() Swaps cases, lower case string.swapcase()
becomes upper case and vice versa
title() Converts the first character of string.title()
each word to upper case translate() Returns a translated string string.translate(table)
upper() Converts a string into upper case string.upper()
zfill() Fills the string with a specified string.zfill(len)