[英]Printing strings that have chars separated by “ + ” and strings themselves separated by “ , ”
I have some variables: 我有一些变量:
A1 = 'abc'
B1 = 'def'
C1 = 'ghi'
I want to write code that prints A1, B1, C1 in the following format: 我想编写以以下格式打印A1,B1,C1的代码:
a+b+c, d+e+f, g+h+i
so in every string value the chars get separated by a +
and the strings themselves are separated by a ,
. 所以在每一个字符串值的字符是不是被分隔+
和本身由一个分隔字符串,
。
How can this be accomplished? 如何做到这一点?
In [11]: str.join?
Namespace: Python builtin
Docstring:
S.join(iterable) -> string
Return a string which is the concatenation of the strings in the
iterable. The separator between elements is S.
In [12]: ", ".join("+".join(chars) for chars in [A1, B1, C1])
Out[12]: 'a+b+c, d+e+f, g+h+i'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.