简体   繁体   中英

Python - Concat variable output to string

I am trying to concat output of a sql output to a string as below:

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)

The above returns

None is the name of the agent

Expected output:

Steve is the name of the agent
a = print(name)

returns None

Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM