Character code learned in Python

Summary of what I learned from reading the Python 2.7 documentation

Unicode HOWTO — Python 2.7.13 documentation https://docs.python.org/2/howto/unicode.html

7.8. codecs — Codec registry and base classes — Python 2.7.13 documentation https://docs.python.org/2/library/codecs.html#encodings-and-unicode

Historical history

Around 1968

Numbers 0-127 were assigned to letters by ASCII (American Standard Code for Information Interchange). Example) a: 97

$ python -V
Python 2.7.10

>>> unichr(97)
u'a'

>>> ord('a')
97

unichr(i) - 2. Built-in Functions — Python 2.7.13 documentation ord(i) - 2. Built-in Functions — Python 2.7.13 documentation

However, the é and Russian Cyrillic letters used in Europe could not be represented.

1980s

8-bit (2 ^ 8 = 256) computers became mainstream, with 128-255 each assigned characters in their own format.

Unicode was developed to eliminate this difference.

Unicode

Definition

The Unicode standard describes how characters are represented by code points.

Character: a code points: 97 (0x61)

Number to use

Initially, Unicode used 16bit (65,536). It currently has a width of 0–1,114,111 (0x10ffff).

a Unicode string is a sequence of code points, which are numbers from 0 to 0x10ffff.

Encodings

The rules for translating a Unicode string into a sequence of bytes are called an encoding.

>>> 'a'.encode('hex')
'61'

Python code

$ python -V
Python 2.7.10

>>> s = 'a b c x y z'
>>> s.encode('hex')
'612062206320782079207a'

vim --Insert mode

ʻAis entered withCTRL-v + u0061`.

reference

Python Character Mapping Codec cp1252 generated from 'MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT' with gencodec.py.

Recommended Posts

Character code learned in Python
python character code
About Python3 character code
Refactoring Learned in Python (Basic)
Python classes learned in chemoinformatics
2.x, 3.x character code of python
What I learned in Python
Python functions learned in chemoinformatics
Character code
[Python] Generate QR code in memory
Automatically format Python code in Vim
Write selenium test code in python
I learned about processes in Python
Elementary ITK usage learned in Python
Code tests around time in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Handling of character code of file in IronPython
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
[Python] Algorithm-aware code
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Disassemble in Python
Reflection in Python
Constant in python
[Python] Get the character code of the file
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Get the EDINET code list in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Notes on using code formatter in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
python> Copy and paste code> SyntaxError: Non-ASCII character'\ xe3' in file>-*-coding: utf-8-*-Add
Python variables and data types learned in chemoinformatics