我有一些变量:打印字符串必须用“+”和字符串自己通过分离分离字符“”
A1 = 'abc'
B1 = 'def'
C1 = 'ghi'
我想写打印A1,B1,C1的格式如下代码:
a+b+c, d+e+f, g+h+i
所以在每一个字符串值的字符是不是被+
分离,字符串本身由,
分开。
这是如何实现的?
我有一些变量:打印字符串必须用“+”和字符串自己通过分离分离字符“”
A1 = 'abc'
B1 = 'def'
C1 = 'ghi'
我想写打印A1,B1,C1的格式如下代码:
a+b+c, d+e+f, g+h+i
所以在每一个字符串值的字符是不是被+
分离,字符串本身由,
分开。
这是如何实现的?
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'
这是功课? – 2013-03-08 23:28:43
umm不,我没有注册任何编程课,我有一个个人项目我正在工作 – KingMak 2013-03-08 23:30:01