Wrap the text in quotes in Python
In Python, text is a string, and you write it inside quotes. Double quotes and single quotes make the same kind of string:
greeting = "I love you"
print(greeting) # I love you
'I love you' works the same way. Pick one style and keep it consistent across your code.
Put quotes inside the text
If the text itself has quotes, use the other kind of quote around it, or escape the inner quote with a backslash:
print('She wrote "I love you" on the card')
print("She wrote \"I love you\" on the card")
Both lines print She wrote "I love you" on the card. A single quote inside double quotes needs no escape, so "It's late, but I love you" works as written.
For text across several lines, use triple quotes:
note = """I love you.
See you soon."""
The string holds a line break between the two sentences.
SQL uses its own quoting rules
In SQL, text values use single quotes, as in 'I love you'. To put an apostrophe inside a single-quoted SQL text value, write two apostrophes in a row:
INSERT INTO notes (body) VALUES ('It''s late, but I love you');
Double quotes mean something different in standard SQL. They mark names, such as a column or table name, not text. MySQL is the exception: it treats double-quoted text as a string unless the ANSI_QUOTES mode is on, so a query that runs in MySQL may not run unchanged elsewhere.
For the choice of text type for a column that holds messages, see the different data types of sql and when to use each.
Save the message with a placeholder
If the message comes from Python, do not paste it into the SQL text. An f-string breaks as soon as the message contains an apostrophe:
message = "It's late, but I love you"
# Breaks: the apostrophe ends the SQL text early
cur.execute(f"INSERT INTO notes (body) VALUES ('{message}')")
# Works: the driver handles the quotes
cur.execute("INSERT INTO notes (body) VALUES (?)", (message,))
conn.commit()
If the text comes from users, the same mistake can also allow SQL injection. The ? placeholder above is the sqlite3 style. Other drivers use other placeholders; see how to pass variable in sql query in python for a table of them.