Python and SQLite: insert into table

后端 未结 6 630
梦如初夏
梦如初夏 2020-12-08 00:08

I have a list that has 3 rows each representing a table row:

>>> print list
[laks,444,M]
[kam,445,M]
[kam,445,M]

How to insert thi

6条回答
  •  独厮守ぢ
    2020-12-08 01:06

    #The Best way is to use `fStrings` (very easy and powerful in python3)   
    #Format: f'your-string'   
    #For Example:
    
    mylist=['laks',444,'M']
    
    cursor.execute(f'INSERT INTO mytable VALUES ("{mylist[0]}","{mylist[1]}","{mylist[2]}")')
    
    #THATS ALL!! EASY!!
    #You can use it with for loop!
    

提交回复
热议问题