keep-loving-pythonのブログ

Pythonを愛し続けたいです(Pythonが流行っている限りですが。。。)

Python、ここは公式ドキュメントを読もうN選(N=2)。

Python、ここは公式ドキュメントを読もうN選(N=2)。

Pythonの説明で、なんとも、簡単には説明できない部分がある。
そのような部分は、あきらめて、公式ドキュメントを読もう!!

【001】ファイルの改行コード

https://docs.python.org/ja/3/tutorial/inputoutput.html

テキストモードの読み取りでは、プラットフォーム固有の行末記号 (Unix では \n 、Windows では \r\n) をただの \n に変換するのがデフォルトの動作です。テキストモードの書き込みでは、 \n が出てくる箇所をプラットフォーム固有の行末記号に戻すのがデフォルトの動作です。

【002】特殊メソッド

https://docs.python.org/ja/3/reference/datamodel.html#special-method-names

object.getitem(self, key) Called to implement evaluation of self[key]. For sequence types, the accepted keys should be integers and slice objects. Note that the special interpretation of negative indexes (if the class wishes to emulate a sequence type) is up to the getitem() method. If key is of an inappropriate type, TypeError may be raised; if of a value outside the set of indexes for the sequence (after any special interpretation of negative values), IndexError should be raised. For mapping types, if key is missing (not in the container), KeyError should be raised.