LoginSignup
12
10

More than 5 years have passed since last update.

Pythonで特定の文字が最後だったら削除する

Last updated at Posted at 2017-08-14

メモです

TCPdumpとかの出力を文字で区切りたい時、IPの最後の文字が":"だったら削除したいって時ありますよね
そういう時は

laststring.py
str="1234:5678:abcd:231a:"

if(str[-1:]==":"):
    print(str[:-1])
else:
    print(str)

でいけます

追記

こっちの方がよかったです

str="1234:5678:abcd:231a:"
print(str.rstrip(':'))
12
10
3

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
12
10