UPDATE — Python Technical Interview Questions & Answers
UPDATE
UPDATE
- UPDATE is about talking to a database from Python. Pattern is always: connect → cursor → execute → fetch or commit → close.
- For UPDATE: use ? placeholders (or the driver’s params). Never build SQL with + user text — that is injection. sqlite3 is in the stdlib for practice; MySQL/Mongo need a driver.
- UPDATE on the board: insert Asha, select her back, print the name. Same idea on MySQL. Close the connection.
- Output: 90. UPDATE then SELECT.
Technical Interview Tip: Steps in order: connect → execute → fetch/commit → close. Mention placeholders.
Code Examples for UPDATE
Example
# UPDATE
import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table t(name text, marks integer)")
cur.execute("insert into t values('Asha', 80)")
cur.execute("update t set marks=? where name=?", (90, "Asha"))
print(cur.execute("select marks from t").fetchone()[0])
con.close()
Output: 90. UPDATE then SELECT.
How to Explain UPDATE to an Interviewer
Explain UPDATE as if you are teaching a junior — definition, then one tiny script.
UPDATE uses connect + cursor + SQL/API. UPDATE — parameterized queries. Never + user text into SQL.
What does the example print, and why?
90
What mistake do freshers make with UPDATE?
UPDATE — commit after write. close when done.