Skip to content

Instantly share code, notes, and snippets.

@mihyaeru21
Created February 13, 2013 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihyaeru21/4943945 to your computer and use it in GitHub Desktop.
Save mihyaeru21/4943945 to your computer and use it in GitHub Desktop.
文字数を数えたいときは unicode型 に対して len() を使え、俺。 エンコードが指定されている時はバイト数が返されるべ。
# UTF-8 な環境です
>>> len("コレハハンカクカナデス")
36
>>> len(u"コレハハンカクカナデス")
12
>>> len("これは全角")
15
>>> len(u"これは全角")
5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment