1
1

【Python】文字列の先頭・末尾n文字を削除する方法

Posted at

◆問題
文字列の先頭・末尾n文字を削除する方法が分からなかった。

◆対処法
スライスを使用すればできた。

slice.py
txt = 'あいうえお'
print(txt[:-2]) #末尾から2文字を削除
print(txt[4:]) #先頭から4文字を削除

# 実行結果
あいう

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1