Python-Concat变量输出到字符串

时间:2018-12-13 12:20:55

标签: python python-3.x variables

我正在尝试将sql输出的输出连接到字符串,如下所示:

dwh_cur.execute("""select name from sales where id = 123""")
name = dwh_cur.fetchone()[0]
a = print(name)
b = str(a) + " is the name of the agent"
print(b)

以上返回

None is the name of the agent

预期输出:

Steve is the name of the agent

1 个答案:

答案 0 :(得分:1)

a = print(name)

不返回

尝试:

b = "{} is the name of the agent".format(name)