Sign in to save your progress, vote, and build your own decks.Sign in
Python string functions
37 cards·by lucrussell
pythoncomputing
capitalize()
Capitalize the first letter
center(width[, fillchar])
Center in a string of length width
count(sub[, start[, end]])
Return the number of occurrences of substring sub in string
decode([encoding[, errors]])
Decodes the string using the codec registered for encoding
encode([encoding[,errors]])
Return an encoded version of the string. Default encoding is the current default string
encoding
endswith(suffix[, start[, end]])
Return True if the string ends with the specified suffix
expandtabs([tabsize])
Return a copy of the string where all tab characters are expanded using space
find(sub[, start[, end]])
Return the lowest index in the string where substring sub is found
index(sub[, start[, end]])
Like find(), but raise ValueError when the substring is not found
isalnum()
True if all characters in the string are alphanumeric and there is at least one character
isalpha()
True if all characters in the string are alphabetic and there is at least one character
isdigit()
True if all characters in the string are digits and there is at least one character
islower()
True if all cased characters in the string are lowercase and there is at least one cased
character
isspace()
True if there are only whitespace characters in the string and there is at least one character
istitle()
True if the string is a titlecased string and there is at least one character
isupper()
True if all cased characters in the string are uppercase and there is at least one cased
character
join(seq)
Concatenate the strings in the sequence seq
ljust(width[, fillchar])
Return is left justified in a string of length width. Padding is done using the specified
fillchar (default is a space)
lower()
Return a copy of the string converted to lowercase
lstrip([chars])
Return a copy of the string with leading characters removed. The chars argument is a string
specifying the set of characters to be removed
partition(sep)
Split the string at the first occurrence of sep, and return a 3-tuple containing the part
before the separator, the separator itself, and th
replace(old, new[, count])
Return a copy of the string with all occurrences of substring old replaced by new
rfind(sub [,start [,end]])
Return the highest index in the string where substring sub is found, such that sub is contained
within s[start,end]
rindex(sub[, start[, end]])
Like rfind() but raises ValueError when the substring sub is not found
rjust(width[, fillchar])
Return the string right justified in a string of length width. Padding is done using the
specified fillchar (default is a space)
rpartition(sep)
Split the string at the last occurrence of sep
rsplit([sep [,maxsplit]])
Return a list of the words in the string, using sep as the delimiter string
rstrip([chars])
Return a copy of the string with trailing characters removed
split([sep [,maxsplit]])
Return a list of the words in the string, using sep as the delimiter string
splitlines([keepends])
Return a list of the lines in the string, breaking at line boundaries
startswith(prefix[, start[, end]])
Return True if string starts with the prefix, otherwise return False
strip([chars])
Return a copy of the string with the leading and trailing characters removed
swapcase()
Return a copy of the string with uppercase characters converted to lowercase and vice versa
title()
Return a titlecased version of the string: words start with uppercase characters, all
remaining cased characters are lowercase
translate(table[, deletechars])
Map characters through the given translation table
upper()
Convert to uppercase
zfill(width)
Pads a numeric string on the left with zeros