目次
str.joinメソッド
str
のjoinメソッド
を使います。
>>> list = ["a", "b", "c"] >>> "/".join(list) 'a/b/c'
- 結合したい文字列のjoinメソッドの引数にリストを渡すと結合した文字列が取得できます。
ただし、リストの中身が文字列じゃないとエラーになるので注意して下さい。
TypeError
>>> list2 = [100, 200, 300] >>> "/".join(list2) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sequence item 0: expected str instance, int found