2
c.execute("INSERT INTO numbers VALUES(?)", (random.randint(0,100),))

If I change the above code, to:

c.execute("INSERT INTO numbers VALUES(?)", (random.randint(0,100)))

I will get ValueError: parameters are of unsupported type.

I don't understand why I need the put a ,? What's the difference?

Thanks!

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
fuiiii
  • 1,359
  • 3
  • 17
  • 33
  • 3
    (because you are using a single element in a tuple) – njzk2 Mar 17 '14 at 16:38
  • 1
    Without the comma, the second argument is not a tuple. It is the *comma* that makes it a tuple, not the parentheses (although they are needed here to remove the ambiguity). – Martijn Pieters Mar 17 '14 at 16:38

1 Answers1

7

It's just basic Python syntax. The second value that c.execute() takes in is a tuple whose syntax requires trailing comma , when you put in just one variable to it.

The amateur programmer
  • 1,238
  • 3
  • 18
  • 38