Skip to content

Instantly share code, notes, and snippets.

@kiwamizamurai
Created November 8, 2019 03:11
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 kiwamizamurai/b779a0dd110cc940ec7b510d60f2fba1 to your computer and use it in GitHub Desktop.
Save kiwamizamurai/b779a0dd110cc940ec7b510d60f2fba1 to your computer and use it in GitHub Desktop.
mojicode.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "mojicode.ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/kiwamizamurai/b779a0dd110cc940ec7b510d60f2fba1/mojicode.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "e29Zc_qC714J",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 68
},
"outputId": "727b9d16-f0ab-4624-db49-3d44bdbf609e"
},
"source": [
"print(ord(\"あ\")) # 文字をUnicodeコードポイントに変換\n",
"print(hex(ord(\"あ\"))) # 16進数に変換(Unicodeコードポイントは16進数で表記されることが多い)\n",
"print(chr(12354)) # Unicodeコードポイントを文字に変換"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"12354\n",
"0x3042\n",
"あ\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "VEBrk_-Q77Cr",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "05427580-9cc8-42dd-b331-9a08b09e7745"
},
"source": [
"'あ'.encode('utf-8') # 3byte"
],
"execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"b'\\xe3\\x81\\x82'"
]
},
"metadata": {
"tags": []
},
"execution_count": 8
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "S-Ktjjj2-0UN",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "4be4b471-7889-42dc-c11a-b4032232a197"
},
"source": [
"\n",
"'あ'.encode('shift_jis') # 2byte"
],
"execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"b'\\x82\\xa0'"
]
},
"metadata": {
"tags": []
},
"execution_count": 9
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "DumhT7Gg-Rw4",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment