Python Practice › SQLite Programs › Program 15

Column names of a query

EasySQLite Programs · 15 of 20

Write a Python program to print the column names of a query result.

Advertisement
Output
['id', 'name', 'email']

Approach

  1. cursor.description.

Solution

Python
import sqlite3 conn = sqlite3.connect(":memory:")conn.execute("CREATE TABLE users (id INTEGER, name TEXT, email TEXT)")cur = conn.execute("SELECT * FROM users")print([col[0] for col in cur.description])
Output
['id', 'name', 'email']

Learn the concept

New to this topic? Read the lesson, then come back.

More sqlite programs

← All 20 SQLite Programs

Leave a Comment