# typing モジュールからCallableをインポート from typing import Callable # 関数を引数に取る関数 # callback の型: 引数(int, int)、戻り値int の関数 def apply_operation( a: int, b: int, callback: Callable[[int, int], int] ) -> int: # ...
寺田 学です。9月の 「Python Monthly Topics」 は、Python 3. 5で導入され、多くの場面で活用されている型ヒント (Type Hints) について、より良い型ヒントの書き方を紹介します。 Pythonの型ヒントとは Pythonは動的型付け言語です。型を指定せずに変数宣言できます ...
Pythonのコレクション型(list, tuple, str, dict, set)は、 すべてイテラブル です。 listやtupleがforループで回せるのは直感的ですが、「str(文字列)」もイテラブルである点は、初学者にとって一つの発見かもしれません。
鈴木たかのり (@takanory) です。今月の 「Python Monthly Topics」 では、Pythonの型ヒントの最近の動き、比較的新しい型ヒントの機能について紹介します。 本連載でも過去にいくつも型ヒント関連の記事があります。このようによりよいPythonコードを書くための ...
I'm surfacing it here because I can never remember whether that discussion is here, or in the typeshed repo, or in the mypy tracker. (Adding str, bytes, unicode, Text, basestring as additional search ...