「Python」strip()メソッドで先頭と末尾の文字列を削除するサンプル

2020年12月10日

書式
文字列.strip(削除文字列)
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-
target = "STA-12345ST"
res = target.strip("ST")
print(res)
#!/usr/bin/ruby # -*- coding: UTF-8 -*- target = "STA-12345ST" res = target.strip("ST") print(res)
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-

target = "STA-12345ST"

res = target.strip("ST")

print(res)

実行結果
>python test.py
A-12345

Python

Posted by arkgame