Operation Result Notes
Returns s after replacing numeric and named formatting references found in
braces {}. (details)
s.index(sub[, start[, end]]) like find(), but raises ValueError when the substring is not found. (2)
s.isalnum() Returns True if all characters in s are alphanumeric, False otherwise. (5)
s.isalpha() Returns True if all characters in s are alphabetic, False otherwise. (5)
s.isdigit() Returns True if all characters in s are digit characters, False otherwise. (5)
s.islower() Returns True if all characters in s are lowercase, False otherwise. (6)
s.isspace() Returns True if all characters in s are whitespace characters, False otherwise. (5)
s.istitle() Returns True if string s is a titlecased string, False otherwise. (7)
s.isupper() Returns True if all characters in s are uppercase, False otherwise. (6)
separator.join(seq) Returns a concatenation of the strings in the sequence seq, separated by string
separator, e.g.: ",".join(['A', 'B', 'C']) -> "A,B,C"
s.ljust/rjust/center(width[,
fillChar=' '])
Returns s left/right justified/centered in a string of length width. (1), (8)
s.lower() Returns a copy of s converted to lowercase.
s.lstrip([chars] ) Returns a copy of s with leading chars (default: blank chars) removed.
s.partition(separ) Searches for the separator separ in s, and returns a tuple (head, sep, tail)
containing the part before it, the separator itself, and the part after it. If the
separator is not found, returns (s, '', '').
s.replace(old, new[, maxCount =-
1])
Returns a copy of s with the first maxCount (-1: unlimited) occurrences of
substring old replaced by new.
(9)
s.rfind(sub[ , start[, end]]) Returns the highest index in s where substring sub is found. Returns -1 if sub
is not found.
(2)
s.rindex(sub[ , start[, end]]) like rfind(), but raises ValueError when the substring is not found. (2)
s.rpartition(separ) Searches for the separator separ in s, starting at the end of s, and returns a
tuple (head, sep, tail) containing the (left) part before it, the separator
itself, and the (right) part after it. If the separator is not found, returns ('', '', s).
s.rstrip([chars]) Returns a copy of s with trailing chars(default: blank chars) removed, e.g.
aPath.rstrip('/') will remove the trailing '/'from aPath if it exists
s.split([ separator[, maxsplit]]) Returns a list of the words in s, using separator as the delimiter string. (10)
s.rsplit([ separator[, maxsplit]]) Same as split, but splits from the end of the string. (10)
s.splitlines([ keepends]) Returns a list of the lines in s, breaking at line boundaries. (11)
s.startswith(prefix [, start[,
end]])
Returns True if s starts with the specified prefix, otherwise returns False.
Negative numbers may be used for start and end.Since 2.5 prefix can also be a
tuple of strings to try.
(2)
s.strip([chars]) Returns a copy of s with leading and trailing chars(default: blank chars)
removed.
s.swapcase() Returns a copy of s with uppercase characters converted to lowercase and vice
versa.
s.title() Returns a titlecased copy of s, i.e. words start with uppercase characters, all
remaining cased characters are lowercase.
s.translate(table[, deletechars='']) Returns a copy of s mapped through translation table table. Characters from
deletechars are removed from the copy prior to the mapping. Since 2.6 table
may also be None (identity transformation) - useful for using translate to
delete chars only.
(12)
s.upper() Returns a copy of s converted to uppercase.
s.zfill(width) Returns the numeric string left filled with zeros in a string of length width.
Notes:
• (1) Padding is done using spaces or the given character.
• (2) If optional argument start is supplied, substring s[start:] is processed. If optional arguments start and end are
supplied, substring s[start:end] is processed.
• (3) Default encoding is sys.getdefaultencoding(), can be changed via sys.setdefaultencoding(). Optional argument
errors may be given to set a different error handling scheme. The default for errors is 'strict', meaning that
encoding errors raise a ValueError. Other possible values are 'ignore' and 'replace'. See also module codecs.
• (4) If optional argument tabsize is not given, a tab size of 8 characters is assumed.
• (5) Returns False if string s does not contain at least one character.
• (6) Returns False if string s does not contain at least one cased character.
• (7) A titlecased string is a string in which uppercase characters may only follow uncased characters and lowercase
characters only cased ones.
• (8) s is returned if width is less than len(s).
• (9) If the optional argument maxCount is given, only the first maxCount occurrences are replaced.
• (10) If separator is not specified or None, any whitespace string is a separator. If maxsplit is given, at most maxsplit
splits are done.
• (11) Line breaks are not included in the resulting list unless keepends is given and true.
• (12) table must be a string of length 256.
Str i ng f orm att ing wit h the % o per a tor
formatString % args --> evaluates to a string
• formatString mixes normal text with C printf format fields :
%[flag][width][.precision] formatCode
where formatCode is one of c, s, i, d, u, o, x, X, e, E, f, g, G, r, % (see table below).
• The flag characters -, +, blank, # and 0 are understood (see table below).
Python 2.7 Quick Reference