3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

文字から Unicode を算出する

Last updated at Posted at 2012-03-19

'あ' の Unicode code (なんかややこしいですね) はなーに?といった場合に、
Python ならきっと 'あ'.code() -> '\u3042' みたいのがあるんじゃないかなーと
漠然と思ってたのですが、探せど探せど見つかりません。(もしあったら教えて下さい)

一応組み込み関数として、ord() という関数があります。

>>> ord('あ')
12354

なんのこっちゃという感じですが、同じく組み込み関数の hex() と組み合わせて
16進に変換すると見慣れた形になります。

>>> hex(ord('あ'))
'0x3402'

The Unicode Consortium の 3040 系文字一覧 (PDF) を見る限り正しそうです。

でももっと簡単な方法というかズバリな方法がありそうな気がします。
(もっともあったところで使い道が思いつかないので、やっぱりないのかもしれません)

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?