mirror of
https://github.com/python/cpython.git
synced 2025-08-05 17:39:02 +00:00
19 lines
554 B
Python
19 lines
554 B
Python
import sqlite3
|
|
|
|
con = sqlite3.connect("mydb")
|
|
|
|
cur = con.cursor()
|
|
SELECT = "select name, first_appeared from people order by first_appeared, name"
|
|
|
|
# 1. Iterate over the rows available from the cursor, unpacking the
|
|
# resulting sequences to yield their elements (name, first_appeared):
|
|
cur.execute(SELECT)
|
|
for name, first_appeared in cur:
|
|
print(f"The {name} programming language appeared in {first_appeared}.")
|
|
|
|
# 2. Equivalently:
|
|
cur.execute(SELECT)
|
|
for row in cur:
|
|
print(f"The {row[0]} programming language appeared in {row[1]}.")
|
|
|
|
con.close()
|