【发布时间】:2021-03-17 13:23:15
【问题描述】:
我试图理解为什么有时会为我的列表创建功能生成双引号而不是单引号。我有一个在多个文本文件上使用过的函数,通常输出是一个带单引号的列表,但现在会生成双引号(当我需要单引号时)。
有人能帮我理解为什么会在此处生成双引号和/或强制使用单引号的方法吗?
for below structure is :
string_text is str
text_list is list
list_text is list
def view(string_text):
text_list = []
for t in list_text:
text_list.append(string_text + """ more text """ + t +
""" more text """)
return text_list
text_list = view(string_text)
附加是特定于我的用例的,但你明白了。为 text_list 生成双引号。
list_text sample = ['a','b','c']
【问题讨论】:
-
双引号在哪里弹出?你能举例说明
list_text中的内容吗? -
是的,编辑了问题
-
string_text is strtext_list is listlist_text is list应该在你的代码中做什么? -
另外,您似乎正在通过连接字符串来创建 SQL 查询,请注意 SQL injection
-
当我运行示例时,我得到单引号。应该没什么区别,但我可以问一下为什么你的字符串使用 docstring 三双引号?
标签: python string text double-quotes single-quotes