Triple quotes are used for strings that span multiple lines. They're a convenient shorthand to write readable indented code in strings. If your string is just one line you don't need them and 'abc' == '''abc'''
(same with double quotes).
See the following example of a longer query string:
"select column1, column2, column3 "\
"from table1 t1"\
" join table2 t2 on t1.some_id_field = t2.another_id_field "\
"where column4 = 1"\
" and column5 is not null"\
" -- and so on"
This is a lot of typing and error prone if you forget the trailing ' '
(so that you get ... column3from ...
). The same with triple quotes is much easier to read and write:
"""select column1, column2, column3
from table1 t1
join table2 t2 on t1.some_id_field = t2.another_id_field
where column4 = 1
and column5 is not null
-- and so on
"""
P.S.: Instead of
table1 = "test1"
query = "".join(("INSERT INTO ", table1," (value0, anycode) VALUES (%s, %s)"))
I'd always use
query = f"INSERT INTO {table1} (value0, anycode) VALUES (%s, %s)"
because it's not only easier to read but it makes it far less probable to forget the spaces around the table name.