LoginSignup
2
1

More than 3 years have passed since last update.

Pythonで「ケツマイモ」と標準出力する方法

Last updated at Posted at 2020-02-02
  • Python3系
print('ケツマイモ')

Python3ではデフォルトでUTF-8をサポートしているのでそのまま「ケツマイモ」を出力します。

  • Python2系
print u'ケツマイモ'
print 'ケツマイモ'.encode('utf-8')
# -*- coding: utf-8 -*-
print 'ケツマイモ'

Python2系では文字列にバイト文字列とユニコード文字列の二種類があり、デフォルトでASCIIをサポートするため、バイト文字列が出力されてしまいます。
「ケツマイモ」のようなマルチバイトなユニコード文字列を表示するためには、バイト文字列をユニコード文字列に変換する必要があります。

2
1
1

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
1