一行Python和SQLite代码,为什么要放“,"? [英] A line of Python and SQLite code, why I need to put ","?
本文介绍了一行Python和SQLite代码,为什么要放“,"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
c.execute("INSERT INTO numbers VALUES(?)", (random.randint(0,100),))
如果我把上面的代码改成:
If I change the above code, to:
c.execute("INSERT INTO numbers VALUES(?)", (random.randint(0,100)))
我会得到ValueError: parameters are unsupported type
.
我不明白为什么我需要放置一个,
?有什么区别?
I don't understand why I need the put a ,
? What's the difference?
谢谢!
推荐答案
这只是基本的 Python 语法.c.execute()
接受的第二个值是一个元组,当您只向其中放入一个变量时,其语法需要尾随逗号 ,
.
It's just basic Python syntax. The second value that c.execute()
takes in is a tuple whose syntax requires trailing comma ,
when you put in just one variable to it.
这篇关于一行Python和SQLite代码,为什么要放“,"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文