Python Programming - Standard Libraries - Discussion
Discussion Forum : Standard Libraries - General Questions (Q.No. 75)
75.
How can you use the
sqlite3
module in Python to connect to an SQLite database and execute a query?
Answer: Option
Explanation:
import sqlite3
# Example usage of sqlite3 module for connecting to an SQLite database and executing a query
connection = sqlite3.connect('example.db')
cursor = connection.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)')
connection.commit()
connection.close()
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers