Connecting Python to a SQLite database
Opens a SQLite database file from Python and returns a connection. Call conn.cursor() on it to get a cursor for running SQL, and conn.close() when finished.
Understanding Connecting Python to a SQLite database in QCE Digital Solutions Unit 2
What it does: import sqlite3 loads the built-in module that provides connect() and the other database tools. conn.close() ends the connection to the database file and frees it up once the work is done. The cursor is made from the connection object (conn), not from the sqlite3 module. SQLite creates the file if it is missing. This is why a misspelt file name gives you a new empty database instead of an error. SQL is run with cur.execute(). conn.cursor() takes no SQL; it only creates the cursor.
Common mistakes: conn.cursor is missing its brackets, so it only refers to the method and does not call it. It should be cur = conn.cursor(). The cursor is created from the connection object, not from the sqlite3 module. It should be cur = conn.cursor().
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 337–409) and word search (Modules 234–409).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
sqlite3.connect()Fill in the Blanks
Spot the Error
Student with a class code? Join your class →