While reading through python sqlite3 DB-API, the first example of creating table uses thee single quotes:
c.execute('''CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real)''')
But in other examples there are double quotes:
cur.execute("create table people (name_last, age)")
So I've got 2 questions:
create table command?Which one is better to use with parameters? ex.:
c.execute('''CREATE TABLE %s(date text, trans text, symbol text, qty
real, price real)''' % table_name)
VS.
cur.execute("create table %s (name_last, age)" % table_name)
Thanks
There is basically no rule for double or single quotes.
But three consecutive quotes start multiline quoted values.
Is this really any difference? How can it affect create table command?
Using single/double quoted string or a triple-quoted string doesn't affect the create command in any way. They are ultimately just string arguments to the create command.
Which one is better to use with parameters?
Double quotes are the norm in most of the python programs. Triple quotes are used mostly when you have a big multi-line string copy-pasted from somewhere else and you want to embed them in your program. In the link that you gave above, we can see one such example in the usage in cursor.executescript(), where an sql script (which probably existed before) is used within the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With