cursor.execute("SELECT price FROM tabel WHERE id = 1600")
print cursor.fetchone()
给我输出
{u'price': u'4345.6'}
如何只选择值4345.6并将其保存在变量中以进行数学运算?
答案 0 :(得分:1)
您可以通过以下代码安静轻松解决此问题。
data = cursor.fetchone() #get the data in data variable
value = float(data['price']) # load the data into value with conversion of its type