gpt4 book ai didi

python - 用于多条 SQL 行的 f 字符串

转载 作者:太空宇宙 更新时间:2023-11-03 21:22:42 29 4
gpt4 key购买 nike

这个有效(只有一行):

   c.execute(f"SELECT Firm, Platform, `Sale in million` FROM database WHERE Platform IN  ({','.join('?' for _ in list_table)}) ORDER BY Firm", (list_table))

但是这些没有(2行):

c.execute(f"SELECT Firm, Platform, `Sale in million` FROM database 
WHERE Platform IN ({','.join('?' for _ in list_table)}) ORDER BY Firm", (list_table))

c.execute(f"SELECT Firm, Platform, `Sale in million` FROM database"
f"WHERE Platform IN ({','.join('?' for _ in list_table)}) ORDER BY Firm", (list_table))"

c.execute("SELECT Firm, Platform, `Sale in million` FROM database"
f"WHERE Platform IN ({','.join('?' for _ in list_table)}) ORDER BY Firm", (list_table))"

如何在多行中使用 f 字符串?

最佳答案

该问题源于本质上无效的多行,而不是 f-string. 的任何错误。 。请注意,您只需在 {} 括号内使用变量,而不是使用 f-string 语法单独传递它们。在字符串末尾使用三引号或反斜杠来使用多行字符串。 Link to docs

test = "this is a 
bad multiline " #Raises SyntaxError: EOL while scanning string literal

test = ''' this is a
valid multiline'''

a = "answer"

print(f'''test
is complete. check {a} ''')

关于python - 用于多条 SQL 行的 f 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54116630/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com