Python: strings and f-strings

10
1

Description

String methods and f-string formatting

Front / BackActions
str.find(sub)
index of the first sub, -1 if absent
f"{value:>10}"
right-aligned in 10 characters
f"{price:.2f}"
a number with two decimals
f"{name!r}"
repr() of the value inside an f-string
str.startswith(prefix)
whether the string begins with prefix
str.replace(old, new)
a copy with every old replaced by new
str.strip(chars=None)
removes leading and trailing characters
str.join(iterable)
joins the strings with str between them
str.partition(sep)
a 3-tuple: before, sep, after; splits at the first sep
str.split(sep=None)
a list of the parts between separators