欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python中executemany和序列的应用 博客分类: python pythonexecutemany序列 

程序员文章站 2024-02-09 11:03:04
...

一 代码

import sqlite3
persons=[
    ("Jim","Green"),
    ("Hu","jie")
    ]
conn=sqlite3.connect(":memory:")
conn.execute("CREATE TABLE person(firstname,lastname)")
conn.executemany("INSERT INTO person(firstname,lastname) VALUES(?,?)",persons)
for row in conn.execute("SELECT firstname,lastname FROM person"):
    print(row)
    
print("I just deleted",conn.execute("DELETE FROM person").rowcount,"rows")

 

二 运行结果
y ========
('Jim', 'Green')
('Hu', 'jie')
I just deleted 2 rows