[英]Format string in python list
I have a list which should contain string with a particular format or character ie {{str(x), str(y)},{str(x), str(y)}}
. 我有一个列表,其中应包含具有特定格式或字符的字符串,即
{{str(x), str(y)},{str(x), str(y)}}
。 I tried to do string concat like: "{{"+str(x), str(y)+"},{"+str(x), str(y)+"}}"
and append to list, but it gets surrounded by brackets: [ ({{str(x), str(y)}),({str(x), str(y)}})
] How can I get rid of the brackets or betterstill, is there a better approach to having a list without brackets like this: [{{string, string},{string, string}}]
我试图做字符串concat像:
"{{"+str(x), str(y)+"},{"+str(x), str(y)+"}}"
并追加到列表,但是被方括号包围:[ ({{str(x), str(y)}),({str(x), str(y)}})
]如何摆脱方括号或更好的方法,是否有更好的方法来获得没有括号的列表,例如: [{{string, string},{string, string}}]
The parentheses are because you're creating a tuple of three items: 括号是因为您要创建三个项目的元组:
"{{"+str(x)
str(y)+"},{"+str(x)
str(y)+"}}"
Try replacing those bare commas between str(x)
and str(y)
with +","+
: 尝试用
+","+
替换str(x)
和str(y)
之间的裸逗号:
"{{"+str(x)+","+str(y)+"},{"+str(x)+","str(y)+"}}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.