K12教育赛事综合服务平台
专注青少年竞赛题库网站
聚乐之家官方网站
下载聚乐之家官方App
有如下Python代码:
import sqlite3 conn=sqlite3.connect('cj.db') cursor=conn.cursor() cursor.execute('SELECT * FROM student') rows=cursor.fetchmany(5) for row in rows: print(row) cursor.close() conn.close()
已知查询的数据表中的数据超过5行。
连接的数据库文件是student
查询的数据表名称是select
若只想获取一条查询数据,可以将fetchmany()换成fetchall()
print(len(rows))得到的结果是5