0

I'm relatively new into Python and I've got a question: How can I input a variable into an SQL execution?

sql = "Insert INTO links VALUES('stackoverflow')"

Obviously, 'stackoverflow' is just a string but what do I need to change if I want to insert a variable?

Thanks for your help! Melodlebron

vaultah
  • 44,105
  • 12
  • 114
  • 143

1 Answers1

-2

what you seem to be needing is a dynamically formatted string, Python has those in the form of:

 stackoverflowString = "stackoverflow"
 sql = ("Insert INTO links VALUES('%s')" % stackoverflowString)

This will replace the string stackoverflowString inside the SQL statement.

Gustavo Gomes
  • 317
  • 5
  • 13