Strings (Cheat Sheet)

String Formatting

>>> number = [10, 11, 12]
>>> text = "Numbers: {0} {1} {2}".format(number[0],number[1], number[2])
>>> print(text)
Numbers: 10 11 12

Joining Strings with a Separator

>>> print(" && ".join(["apple pie","motherhood"]))
apple pie && motherhood

Replacements

>>> print("Good morning !".replace("morning", "afternoon"))
Good afternoon!

Check for the Ending

>>> print("Good morning!".endswith("morning!"))
True
>>> print("Good morning!".endswith("morning"))
False

Check for the Beginning

>>> print("Good morning".startswith("Lousy"))
False

Capitilize Strings and lower them as well...

>>> print("Good morning".upper())
GOOD MORNING
>>> print("Good morning".lower())
good morning

Split Strings and turn them into Lists

>>> print("Motherhood, and, apple pie".split(", "))
['Motherhood', 'and', 'apple pie']