[Introduction to Python3 Day 13] Chapter 7 Strings (7.1-7.1.1.1)

7.1 string

7.1.1 Unicode

--The basic unit of computer memory is ** bytes **, which can represent 256 unique values using 8 bits. --Bits: The number of digits in a binary number (0 and 1, binary). 4-bit is a 4-digit number and 8-bit is an 8-digit binary number, which can represent 2 to the 4th power (16) and 2 to the 8th power (256), respectively. --Bytes: 1 byte with 8 bits. It is easier to understand if you use a hexadecimal number to represent one byte.

--Unicode is a developing international standard that seeks to define symbols in all literature and mathematics of the world's languages and other disciplines.

7.1.1.1 Python 3 Unicode strings

--The Python3 string is a Unicode string, not a byte string. --If you know the Unicode ID or name of a character, you can use it in a Python string. --Python's unicodedata module contains a bidirectional conversion function. --lookup (): Given a name (case insensitive), Unicode characters are returned. --name (): Given Unicode characters, uppercase names are returned.


>>> def unicode_test(v):
...     import unicodedata
#Extract the name from the letters
...     name=unicodedata.name(v)
#Extract the string from the name.
...     v2=unicodedata.lookup(name)
...     print("v=%s,name=%s,v2=%s"%(v,name,v2))
... 
>>> unicode_test("A")
v=A,name=LATIN CAPITAL LETTER A,v2=A

#Unicode ASCII symbols
>>> unicode_test("$")
v=$,name=DOLLAR SIGN,v2=$
#Unicode currency symbol
>>> unicode_test("\u00a2")
v=¢,name=CENT SIGN,v2=¢
>>> unicode_test("\u20ac")
v=€,name=EURO SIGN,v2=€
#Display of alternative symbols
>>> unicode_test("\u2603")
v=☃,name=SNOWMAN,v2=☃


>>> place = "cafe"
>>> place
'cafe'
>>> import unicodedata
>>> unicodedata.name('\u00e9')
'LATIN SMALL LETTER E WITH ACUTE'
>>> unicodedata.lookup('LATIN SMALL LETTER E WITH ACUTE')
'é'
#Specify a character string by code
>>> place = "caf\u00e9"
>>> place
'café'
#Specify a character string by name
>>> place = "caf\N{LATIN SMALL LETTER E WITH ACUTE}"
>>> place
'café'

>>> u="\N{LATIN SMALL LETTER U WITH DIAERESIS}"
>>> u
'ü'

#len()Counts Unicode characters, not bytes.
>>> len("&")
1
>>> len("\U0001f47b")
1


Impressions

There are quite a few words that I don't remember hearing, such as encoding, decoding, and byte strings. Let's check each one.

References

"Introduction to Python3 by Bill Lubanovic (published by O'Reilly Japan)"

Recommended Posts

[Introduction to Python3 Day 13] Chapter 7 Strings (7.1-7.1.1.1)
[Introduction to Python3 Day 14] Chapter 7 Strings (7.1.1.1 to 7.1.1.4)
[Introduction to Python3 Day 15] Chapter 7 Strings (7.1.2-7.1.2.2)
[Introduction to Python3 Day 21] Chapter 10 System (10.1 to 10.5)
[Introduction to Python3, Day 17] Chapter 8 Data Destinations (8.1-8.2.5)
[Introduction to Python3, Day 17] Chapter 8 Data Destinations (8.3-8.3.6.1)
[Introduction to Python3 Day 19] Chapter 8 Data Destinations (8.4-8.5)
[Introduction to Python3 Day 18] Chapter 8 Data Destinations (8.3.6.2 to 8.3.6.3)
[Introduction to Python3 Day 3] Chapter 2 Py components: Numbers, strings, variables (2.2-2.3.6)
[Introduction to Python3 Day 2] Chapter 2 Py Components: Numbers, Strings, Variables (2.1)
[Introduction to Python3 Day 4] Chapter 2 Py Components: Numbers, Strings, Variables (2.3.7-2.4)
[Introduction to Python3 Day 12] Chapter 6 Objects and Classes (6.3-6.15)
[Introduction to Python3 Day 22] Chapter 11 Concurrency and Networking (11.1 to 11.3)
[Introduction to Python3 Day 11] Chapter 6 Objects and Classes (6.1-6.2)
[Introduction to Python3 Day 23] Chapter 12 Become a Paisonista (12.1 to 12.6)
[Introduction to Python3 Day 20] Chapter 9 Unraveling the Web (9.1-9.4)
[Introduction to Python3 Day 8] Chapter 4 Py Skin: Code Structure (4.1-4.13)
[Introduction to Python3 Day 1] Programming and Python
[Introduction to Udemy Python3 + Application] 11. Character strings
Introduction to Effectiveness Verification Chapter 1 in Python
Introduction to Python language
Introduction to OpenCV (python)-(2)
[Introduction to Python3 Day 5] Chapter 3 Py Tools: Lists, Tuples, Dictionaries, Sets (3.1-3.2.6)
[Introduction to Python3 Day 10] Chapter 5 Py's Cosmetic Box: Modules, Packages, Programs (5.4-5.7)
[Introduction to Python3 Day 9] Chapter 5 Py's Cosmetic Box: Modules, Packages, Programs (5.1-5.4)
[Introduction to Python3 Day 6] Chapter 3 Py tool lists, tuples, dictionaries, sets (3.2.7-3.2.19)
Introduction to effectiveness verification Chapter 3 written in Python
Introduction to Effectiveness Verification Chapter 2 Written in Python
Introduction to Python Django (2) Win
Introduction to serial communication [Python]
[Introduction to Python] <list> [edit: 2020/02/22]
Introduction to Python (Python version APG4b)
An introduction to Python Programming
Introduction to Python For, While
[Chapter 5] Introduction to Python with 100 knocks of language processing
[Chapter 3] Introduction to Python with 100 knocks of language processing
[Chapter 2] Introduction to Python with 100 knocks of language processing
[Technical book] Introduction to data analysis using Python -1 Chapter Introduction-
[Chapter 4] Introduction to Python with 100 knocks of language processing
[Introduction to Udemy Python 3 + Application] 58. Lambda
[Introduction to Udemy Python 3 + Application] 31. Comments
Introduction to Python Numerical Library NumPy
Practice! !! Introduction to Python (Type Hints)
[Introduction to Python] <numpy ndarray> [edit: 2020/02/22]
Introduction to Python Hands On Part 1
[Introduction to Python] How to parse JSON
[Introduction to Udemy Python 3 + Application] 56. Closure
Introduction to Protobuf-c (C language ⇔ Python)
[Introduction to Udemy Python3 + Application] 59. Generator
[Introduction to Python] Let's use pandas
[Introduction to Python] Let's use pandas
[Introduction to Udemy Python 3 + Application] Summary
Python day 1
Introduction to image analysis opencv python
[Introduction to Python] Let's use pandas
An introduction to Python for non-engineers
Introduction to Python Django (2) Mac Edition
[AWS SAM] Introduction to Python version
[Python Tutorial] An Easy Introduction to Python
Python learning memo for machine learning by Chainer Chapter 8 Introduction to Numpy
Python learning memo for machine learning by Chainer Chapter 10 Introduction to Cupy