0

私はいくつかの変数を持っています:

A1 = 'abc'
B1 = 'def'
C1 = 'ghi'

A1、B1、C1 を次の形式で出力するコードを書きたいと思います。

a+b+c, d+e+f, g+h+i

したがって、すべての文字列値で、文字は a で区切られ+、文字列自体は a で区切られます,

これはどのように達成できますか?

4

1 に答える 1

2
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-08T23:28:44.487 に答える