· 8 years ago · Jul 21, 2018, 10:10 PM
1# we will use SQLite (light weight disk-based database)
2
3import sqlite3
4
5# create connection (it will create or open example.db file)
6con = sqlite3.connect("carsdb.db")
7
8# cursor is a control that allow to travel across the records in a database
9c = con.cursor()
10
11c.execute("create table if not exists cars(brand text, price text)")
12c.execute("insert into cars (brand, price) values ('bmw', 3000)")
13result = c.execute("select * from cars")
14
15print(result.fetchone())
16
17# ---------------- OUTPUT ----------------
18# ('bmw', '3000')