Python 文字列の前後の改行を削除するサンプル

環境
Windows 11 Pro 64bit
Python 3.11

構文
文字列.strip()
文字列の前後の改行を削除するには、strip()を使います。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
text = "\nstudy skill\n"
res = text.strip()
print(res)
text = "\nstudy skill\n" res = text.strip() print(res)
text = "\nstudy skill\n"

res = text.strip()

print(res)

実行結果
study skill

Python

Posted by arkgame