Run ❯
Get your
own Python
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Change Language
Go to Spaces
Ctrl+Alt+P
import sqlite3 con = sqlite3.connect(":memory:") cur = con.cursor() # The database is in memory, so it is # empty every time the program starts. # Create the table and add the rows: cur.execute(""" CREATE TABLE Shippers ( ShipperID INTEGER PRIMARY KEY, ShipperName TEXT, Phone TEXT ) """) cur.execute(""" INSERT INTO Shippers VALUES (1, 'Speedy Express', '(503) 555-9831'), (2, 'United Package', '(503) 555-3199'), (3, 'Federal Shipping', '(503) 555-9931') """) con.commit() shippers = [ ("Fast Bikes", "(503) 555-1234"), ("Slow Boats", "(503) 555-9876"), ] sql = """ INSERT INTO Shippers (ShipperName, Phone) VALUES (?, ?) """ cur.executemany(sql, shippers) con.commit() cur.execute("SELECT * FROM Shippers") for row in cur.fetchall(): print(row)
(1, 'Speedy Express', '(503) 555-9831')
(2, 'United Package', '(503) 555-3199')
(3, 'Federal Shipping', '(503) 555-9931')
(4, 'Fast Bikes', '(503) 555-1234')
(5, 'Slow Boats', '(503) 555-9876')