A string is a piece of text. You write one by wrapping characters in quotes, and Python accepts single or double quotes with no difference in meaning:
name = 'web-01'
role = "database"
Pick whichever quote keeps you from having to escape. If the text itself contains a single quote, wrap it in double quotes, and the other way round:
message = "it's healthy"
path = 'the "prod" cluster'
A backslash starts an escape sequence. The two you will meet most are
\n for a newline and \t for a tab:
print("line one\nline two")
That prints across two lines. To put a literal backslash in a string,
double it as \\.
Triple quotes, either ''' or """, let a string span several lines
exactly as written:
banner = """
deploy-bot
version 1.0
"""
These are handy for blocks of text like a config template or a usage message.
The + operator joins strings end to end, and * repeats one:
full = "web" + "-" + "01" # "web-01"
rule = "=" * 20 # twenty equals signs
Joining with + only works between strings. To join a string to a
number you must convert the number first with str(), which the
previous topic covered.
The built-in len() function returns how many characters a string
holds:
print(len("web-01")) # 6
len() shows up constantly - checking whether input is empty, or
whether a value is too long before you use it.