Effective Python Memo Item 3

Notes on Effective Python

Item 3: Know the difference between bytes, str, unicode (p5 ~ p7)

** In python, if you don't understand string processing, you will fall into a pitfall. ** **

In particular

--In python2, the strings are str and unicode

--In python3, the strings are str and bytes --str and bytes cannot be used together in operators --str defaults to unicode (although you can use u'' separately ...) --encode from str to bytes --bytes to str is decode

** Common pitfalls ** --In python2, when handling ASCII (7bit), if it is within the range of ASCII characters, it works without specifying str or unicode, but if it exceeds that range, the character code gets lost and an exception occurs. --In python3, the processing related to file operations is set to UTF-8 by default. An error occurs when trying to write binary data (which seems to be the point where python2 people stumble). It is better to set it to'wb'(binary writing) instead of'w' in encoding.

Recommended Posts

Effective Python Memo Item 3
Effective Python memo Item 10 Enumerate from range
Python memo
python memo
python memo
Python memo
Python memo
Python memo
[Python] Memo dictionary
python beginner memo (9.2-10)
Effective Python Memo Item 9 Consider generator expressions for large comprehensions
★ Memo ★ Python Iroha
Effective Python Memo Item 19 Give optional behavior to keyword arguments
[Python] EDA memo
Python 3 operator memo
[My memo] python
[Python] Basemap memo
Python beginner memo (2)
[Python] Numpy memo
My python environment memo
Python module (Python learning memo ④)
Visualization memo by Python
Python test package memo
Effective Python Memo Item 4 Write a helper function instead of a complicated expression
[Python] Memo about functions
python regular expression memo
Binary search (python2.7) memo
[My memo] python -v / python -V
Python3 List / dictionary memo
[Memo] Python3 list sort
Python Tips (my memo)
[Python] Memo about errors
DynamoDB Script Memo (Python)
Effective Python memo Item 7 Use list comprehension instead of map and filter
[Effective Python study memo] Chapter 1: Python-style thinking (Pythonic Thinking)
Python basic memo --Part 2
python recipe book Memo
Effective Python Memo Item 8 Avoid three or more expressions in list comprehensions
Basic Python command memo
Python OpenCV tutorial memo
Python basic grammar memo
TensorFlow API memo (Python)
python useful memo links
Python decorator operation memo
Python basic memo --Part 1
Divisor enumeration Python memo
Effective Python Memo Item 18 Use variable-length positional arguments to make the appearance cleaner
Effective Python Learning Memorandum Day 15 [15/100]
Python memo (for myself): Array
Python exception handling (Python learning memo ⑥)
Python execution time measurement memo
Twitter graphing memo with Python
Effective Python Learning Memorandum Day 6 [6/100]
Effective Python Learning Memorandum Day 12 [12/100]
Effective Python Learning Memorandum Day 9 [9/100]
[Line / Python] Beacon implementation memo
Effective Python Learning Memorandum Day 8 [8/100]
Python and ruby slice memo
Python code memo for yourself
Raspberry Pi + Python + OpenGL memo
Python basic grammar (miscellaneous) Memo (3)