組み込み定数¶
組み込み名前空間にはいくつかの定数があります。定数の一覧:
- False¶
bool
型の偽値です。False
への代入は不正で、SyntaxError
を送出します。
- True¶
bool
型の真値です。True
への代入は不正で、SyntaxError
を送出します。
- None¶
関数にデフォルト引数が渡されなかったときなどに、値の非存在を表すのに頻繁に用いられるオブジェクトです。
None
への代入は不正で、SyntaxError
を送出します。None
がNoneType
型の唯一のインスタンスです。
- NotImplemented¶
A special value which should be returned by the binary special methods (e.g.
__eq__()
,__lt__()
,__add__()
,__rsub__()
, etc.) to indicate that the operation is not implemented with respect to the other type; may be returned by the in-place binary special methods (e.g.__imul__()
,__iand__()
, etc.) for the same purpose. It should not be evaluated in a boolean context.NotImplemented
is the sole instance of thetypes.NotImplementedType
type.注釈
When a binary (or in-place) method returns
NotImplemented
the interpreter will try the reflected operation on the other type (or some other fallback, depending on the operator). If all attempts returnNotImplemented
, the interpreter will raise an appropriate exception. Incorrectly returningNotImplemented
will result in a misleading error message or theNotImplemented
value being returned to Python code.例として 算術演算の実装 を参照してください。
注釈
NotImplementedError
andNotImplemented
are not interchangeable, even though they have similar names and purposes. SeeNotImplementedError
for details on when to use it.バージョン 3.9 で変更: Evaluating
NotImplemented
in a boolean context is deprecated. While it currently evaluates as true, it will emit aDeprecationWarning
. It will raise aTypeError
in a future version of Python.
- Ellipsis¶
Ellipsis リテラル "
...
" と同じです。 主に拡張スライス構文やユーザ定義のコンテナデータ型において使われる特殊な値です。Ellipsis
がtypes.EllipsisType
型の唯一のインスタンスです。
注釈
名前 None
、 False
、 True
、 __debug__
は再代入できない (これらに対する代入は、たとえ属性名としてであっても SyntaxError
が送出されます) ので、これらは「真の」定数であると考えられます。
site
モジュールで追加される定数¶
site
モジュール (-S
コマンドラインオプションが指定されない限り、スタートアップ時に自動的にインポートされます) は組み込み名前空間にいくつかの定数を追加します。それらは対話的インタープリタシェルで有用ですが、プログラム中では使うべきではありません。
- quit(code=None)¶
- exit(code=None)¶
表示されたときに "Use quit() or Ctrl-D (i.e. EOF) to exit" のようなメッセージを表示し、呼び出されたときには指定された終了コードを伴って
SystemExit
を送出するオブジェクトです。
- license¶
表示されたときに "Type license() to see the full license text" というメッセージを表示し、呼び出されたときには完全なライセンスのテキストをページャのような形式で (1画面分づつ) 表示するオブジェクトです。