[WIP] Fluent Python Study Note

Hello, everyone, is Eiringu.

This article is a study memorandum of Fluent Python. It will be updated from time to time.

Honestly, I don't read through programming language textbooks seriously, but when I read a book that explains a language properly, I have proper coding skills and discoveries, unlike what I learn ad hoc in practice. .. So, I would like to make a note of what I was interested in with Fluent Python.

Chapter 1

** P.8 Footnote **

In Python 2, you have to explicitly write FrenchDeck (object), but in Python 3, this is the default.

...what...!?

Chapter 2

P.45

2.7 list.sort and built-in function sorted

The list.sort method sorts the list in-place and does not make a copy. You can tell from the fact that None is returned that you are modifying the target object without creating a new list. (Omitted) On the other hand, the built-in function sorted creates a new list and returns it.

Hmm. I used to sort the list and save it to myself, so I used it as a reference.

2.9.1 Array

ʻArray.array is more efficient than list when the list contains only numbers. ... (Omitted) ... Python arrays are as efficient as C arrays. ʻArray is created by specifying the type code, because the type of the element stored in the array is supported by the internal C data type.

Lists also use only about the same type of data, so it would be more efficient if we started using arrays. I've never done a professional computer, but if you don't know this area, it won't work.

Chapter 3

P. 76

my_dict.setdefault(key, []).append(new_value) This is operationally the same as:

if key not in my_dict:
    my_dict[key] = []
my_dict[key].append(new_value)

The method of using the ʻif` statement is easy to do, so be careful.

Chapter 4

The extra is b'\ xff \ xfe. These are ** BOM ** * (byte-order mark) *, which represent the "little endian" byte order of the Intel CPU that performed the encoding. ~ Omitted ~ The standard stipulates that if the file is UTF-16 and there is no BOM there, then UTF-16BE (Big Endian) should be assumed. However, the Intel x86 architecture is little endian, and there are many little endian UTF-16s out there without a BOM. Endian issues only affect encodings that make up a word with multiple bytes, such as UTF-16 and UTF-32. One of the great advantages of UTF-8 is that it produces the same sequence of bytes regardless of the endianness of the machine. No BOM required. Nevertheless, some Windows applications add BOM to UTF-8 files (especially Notepad). Excel's UTF-8 file detection relies on BOM, without BOM assuming that the content is encoded in a Windows code page.

Ah, so if you load csv / tsv written in Python with Excel, the characters will be garbled. It doesn't recognize it as utf-8 by default.

Recommended Posts

[WIP] Fluent Python Study Note
Python study note_002
Python study note_004
Python study note_003
Note: Python
Python note
Note: Python Decorator
Python programming note
[Python] Learning Note 1
Python study notes _000
Python study notes_006
Python study notes _005
Jupyter Study Note_002
[Note] openCV + python
Python beginner's note
Python study notes_001
Jupyter Study Note_003
Jupyter Study Note_007
Jupyter Study Note_005
Python study day 1
[Note] future sentence ~ Python ~
[Note] File reading ~ Python ~
Note to daemonize python
Note: python Skeleton Nya
Python basic grammar note (4)
Python basic grammar note (3)
Python Tkinter Primer Note
Study Python with Google Colaboratory
Study from Python Hour4: Object-oriented ②
[Note] Operate MongoDB with Python
Study from Python Hour3: Functions
python pandas study recent summary
3 months note for starting Python
Study from Python Hour4: Object-oriented ①
[AtCoder] ABC165C Personal Note [Python]
Note that it supports Python 3
A note about [python] __debug__
Python Note: About comparison using is
[Note] Project Euler in Python (Problem 1-22)
Python: A Note About Classes 1 "Abstract"
selenium case study summary python pyCharm
(Note) Be careful with python argparse
Study on Tokyo Rent Using Python (3-2)
[Note] Hello world output with python
boto3 (AWS SDK for Python) Note
Foreign Key in Python SQLite [Note]
Study on Tokyo Rent Using Python (3-3)
Study, number guessing game in Python
Study Note 9_Install Jenkins on CentOS7
Python Note: Get the current month
A note about mock (Python mock library)
Basic study of OpenCV with Python