Python joinメソッドを使ってタプルの値を文字列として連結する

環境
Python 3.9.13
Windows 10 Home 64bit
PyCharm 2022.2.1 (Community Edition)

構文
'区切り文字’.join(タプル名)
タプルにをjoin()メソッドで連結した場合、区切り文字で繋いだ連結した文字列を新たに返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
data = ('study', 'skill', 'become', 'smart')
res = '*'.join(data)
print(res)
data = ('study', 'skill', 'become', 'smart') res = '*'.join(data) print(res)
data = ('study', 'skill', 'become', 'smart')
res = '*'.join(data)
print(res)

実行結果
study*skill*become*smart

Python

Posted by arkgame