python用列表形式写入CSV文件

csv.writer(f):
writer支持writerow(列表)单行写入,和writerows(嵌套列表)批量写入多行,无须手动保存。

import csv

header = ['name','age','QQ_num','wechat']

data = [['suliang','21','787991021','lxzy787991021']]
with open ('information.csv','w',encoding='utf-8',newline='') as fp:
    # 写
    writer =csv.writer(fp)
    # 设置第一行标题头
    writer.writerow(header)
    # 将数据写入
    writer.writerows(data)