0% found this document useful (0 votes)
18 views5 pages

Understanding Python String Methods

Uploaded by

thulavenu3579
Copyright
© All Rights Reserved
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
0% found this document useful (0 votes)
18 views5 pages

Understanding Python String Methods

Uploaded by

thulavenu3579
Copyright
© All Rights Reserved
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

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 [Link]()


upper case

casefold() Converts string into lower case [Link]()

center() Returns a centered string [Link](length,charact


er)

count() Returns the number of times a [Link](value, start,


specified value occurs in a string end)

encode() Returns an encoded version of [Link](encoding=enc


the string oding, errors=errors)

endswith() Returns true if the string ends [Link](value, start,


with the specified value end)

expandtabs( Sets the tab size of the string [Link](tabsize)


)

find() Searches the string for a [Link](value, start, end)


specified value and returns the
position of where it was found

format() Formats specified values in a [Link](value1,


string value2...)
format_map Formats specified values in a
() string

index() Searches the string for a [Link](value, start,


specified value and returns the end)
position of where it was found

isalnum() Returns True if all characters in [Link]()


the string are alphanumeric

isalpha() Returns True if all characters in [Link]()


the string are in the alphabet

isascii() Returns True if all characters in [Link]()


the string are ascii characters

isdecimal() Returns True if all characters in [Link]()


the string are decimals

isdigit() Returns True if all characters in [Link]()


the string are digits

isidentifier( Returns True if the string is an [Link]()


) identifier

islower() Returns True if all characters in [Link]()


the string are lower case

isnumeric() Returns True if all characters in [Link]()


the string are numeric

isprintable() Returns True if all characters in [Link]()


the string are printable
isspace() Returns True if all characters in [Link]()
the string are whitespaces

istitle() Returns True if the string follows [Link]()


the rules of a title

isupper() Returns True if all characters in [Link]()


the string are upper case

join() Converts the elements of an [Link](iterable)


iterable into a string

ljust() Returns a left justified version of [Link](length,


the string character)

lower() Converts a string into lower case [Link]()

lstrip() Returns a left trim version of the [Link](characters)


string

maketrans() Returns a translation table to be [Link](x, y, z)


used in translations

partition() Returns a tuple where the string [Link](value)


is parted into three parts

replace() Returns a string where a [Link](oldvalue,


specified value is replaced with a newvalue, count)
specified value

rfind() Searches the string for a [Link](value, start,


specified value and returns the end)
last position of where it was
found
rindex() Searches the string for a [Link](value, start,
specified value and returns the end)
last position of where it was
found

rjust() Returns a right justified version [Link](length,


of the string character)

rpartition() Returns a tuple where the string [Link](value)


is parted into three parts

rsplit() Splits the string at the specified [Link](separator,


separator, and returns a list maxsplit)

rstrip() Returns a right trim version of [Link](characters)


the string

split() Splits the string at the specified [Link](separator,


separator, and returns a list maxsplit)

splitlines() Splits the string at line breaks [Link](keeplinebre


and returns a list aks)

startswith() Returns true if the string starts [Link](value,


with the specified value start, end)

strip() Returns a trimmed version of the [Link](characters)


string

swapcase() Swaps cases, lower case [Link]()


becomes upper case and vice
versa

title() Converts the first character of [Link]()


each word to upper case
translate() Returns a translated string [Link](table)

upper() Converts a string into upper case [Link]()

zfill() Fills the string with a specified [Link](len)


number of 0 values at the
beginning

You might also like