Sign in to save your progress, vote, and build your own decks.Sign in
Python string API
26 cards·by megsmitley
pythoncomputing
s.capitalize()
Capitalizes first letter of s.
s.center(witdth)
Returns space-padded s with original s centered to a total of width columns.
s.count(str, beg=0, end=len(s))
Counts occurrences of str in s, or in a substring of s if starting index beg and ending index end
are given.
s.decode(encoding=
Returns decoded string version of s; on error, default raises ValueError unless errors set to
s.encode(encoding='UTF-8', errors='strict')
Returns encoded string version of s; on error, default raises ValueError unless errors set to
s.endswith(obj, beg=0, endlen(s))
Determines if s or substring of s (if beg and end indexes given) ends with obj where obj is
typically a string; if obj is a tuple, then any
s.expandtabs(tabsize=8)
Expand tabs in s to multiple spaces; default tab size 8 spaces.
s.find(str, beg=0, end=len(s))
Determines if str occurs in s, or ina substring of s if beg and end indexes set; returns index if
found else -1.
s.index(str, beg=0, end=len(s))
Same as find(), but raises exception if str not found.
s.isalnum()
Returns True is s has at least 1 character and all characters are alphanumeric, else False.
s.isalpha()
Returns True if s has at least 1 character and all characters are alphabetic.
s.isdecimal()
Returns True is s contains only deicmal digits, else False.
s.isdigit()
Returns Rue if s contains only digits, else False.
s.islower()
Returns True is s has at least 1 cased character and all cased characters are lowercased, else
False.
s.isnumeric()
Returns True is s contains only numeric characters, else False.
s.isspace()
Returns True if s contains only whitespce characters, else False.
s.istitle()
Returns True is s 'titlecase' (see title()), else False.
s.isupper()
Returns True is s has at least 1 cased character and all cased characters uppercased, else
False.
s.join(seq)
Concatenates the string representations of elements sequence seq into a string with
separator s.
s.ljust(width)
Returns space-padded s with original s left-justified to a total of width colums).
s.lower()
Converts all uppercased letters in s to lowercase.
s.lstrip()
Removes all leading whitespace in s.
s.partition(str)
Splits s into 3-tuple (string_pre_str, str, string_post_str) on first occurrence of str,
else string_pre_str == s.
s.replace(str1, str2, num=s.count(str1))
Replaces all occurrences of str1 in string with str2, or at most num occurrences if num given).
s.rfind(str, beg=0, end=len(s))
Same as find(), but searches from right in s.
s.rindex(str)
Same as index(), but searches from right in s.