import sqlite3 # Link Database con = sqlite3.connect('C:\python_learn\DBA\SQLite3demo\sqlite3demo.db') # Create a cursor object cur = con.cursor() # Write sql statement sql = "delete from t_person where pno = ?" # Sql execution try: cur.execute(sql,(1)) con.commit () print ( "deleted successfully") except Exception as e: print (e) print ( "Delete failed") con.rollback() finally: # Close the connection # Close the cursor cur.close() con.close()
Deleted data is a tuple type, and therefore should be followed by a comma 1, modified cur.execute (sql, (1,), can be performed successfully;