LoginSignup
2
3

More than 5 years have passed since last update.

文字列前後の全角スペースを除去する (python)

Posted at

小ネタです.

test.py
line = '  本日の天気は晴天なり 晴天なり  '
NG_example = line.strip()    # ' 本日の天気は晴天なり 晴天なり '
OK_example = unicode(line).strip()    # u'本日の天気は晴天なり 晴天なり'
OK_example2 = line.decode('utf-8').strip().encode('utf-8')    # '本日の天気は晴天なり 晴天なり'
2
3
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
2
3