Pythonで文字列への挿入・置換
文字の挿入
text = 'Hello {}!'.format('World') print(text) #Hello World! text = '{0} is a {1}.'.format('This', 'pen') print(text); #This is a pen.
文字列の置換(全置換)
text = 'pen pineapple apple pen.' text = text.replace("apple","orange") print(text); #pen pineorange orange pen.
文字列の置換(1つ目のみ置換)
text = 'pen pineapple apple pen.' text = text.replace("apple","orange", 1) print(text); #pen pineorange apple pen.
[ad#ad-1]
スポンサーリンク