3. 組み込み定数

組み込み名前空間にはいくつかの定数があります。定数の一覧:

False

bool 型の偽値です。False への代入は不正で、SyntaxError を送出します。

True

bool 型の真値です。True への代入は不正で、SyntaxError を送出します。

None

NoneType の唯一の値です。 None は、関数にデフォルト引数が渡されなかったときなどに、値の非存在を表すのに頻繁に用いられます。 None への代入は不正で、SyntaxError を送出します。

NotImplemented

特殊な二項演算のメソッド (e.g. __eq__(), __lt__(), __add__(), __rsub__(), etc.) が、他の型に対して演算が実装されていないことを示すために返す特殊値です。インプレースの特殊な二項演算のメソッド (e.g. __imul__(), __iand__(), etc.) も同じ理由でこの値を返すことがあります。真偽値は真です。

注釈

When NotImplemented is returned, the interpreter will then try the reflected operation on the other type, or some other fallback, depending on the operator. If all attempted operations return NotImplemented, the interpreter will raise an appropriate exception.

See 算術演算の実装 for more details.

Ellipsis

The same as .... Special value used mostly in conjunction with extended slicing syntax for user-defined container data types.

__debug__

この定数は、Python が -O オプションを有効にして開始されたのでなければ真です。 assert 文も参照して下さい。

注釈

名前 NoneFalseTrue__debug__ は再代入できない (これらに対する代入は、たとえ属性名としてであっても SyntaxError が送出されます) ので、これらは「真の」定数であると考えられます。

3.1. site モジュールで追加される定数

site モジュール (-S コマンドラインオプションが指定されない限り、スタートアップ時に自動的にインポートされます) は組み込み名前空間にいくつかの定数を追加します。それらは対話的インタープリタシェルで有用ですが、プログラム中では使うべきではありません。

quit(code=None)
exit(code=None)

表示されたときに "Use quit() or Ctrl-D (i.e. EOF) to exit" のようなメッセージを表示し、呼び出されたときには指定された終了コードを伴って SystemExit を送出するオブジェクトです。

license
credits

Objects that when printed, print a message like "Type license() to see the full license text", and when called, display the corresponding text in a pager-like fashion (one screen at a time).