Python Basics: Built-in constants

Source: Internet
Author: User

This article according to Python 3.6.5 frustration built-in constants writing, the official text is relatively short, we can directly see the original text.

There are constants that exist in the built-in namespaces (the built-in namespace), as follows:

False

True

All two of the above are bool types and cannot be assigned values.

None

The unique value of type Nonetype. None is often used to denote a worthwhile absence and is not passed to the function as a default parameter.

Nor can it be assigned a value.

notimplemented

The explanation for this constant is more, and should be more complicated. The solitary understanding is that the literal meaning, the hint did not realize.

This is a special value that will be used by some binary magic methods (the binary special methods, e.g. __eq__ (), __lt__ (), __add__ (), __rsub__ (), etc.) returns, used to indicate that the execution of these methods on some types failed without providing a corresponding implementation; There are also some in-place two-dollar magic methods (e.g. __imul__ (), __iand__ ()) also return this constant for the same purpose.

It is true.

Note: When the binary magic method above returns notimplemented, the interpreter uses this method for other types. If all attempts are returned notimplemented, the interpreter will produce the corresponding exception. Incorrect return notimplemented causes the error message to be misunderstood, or the notimplemented value is returned to Python code (then?). )。

Note: Notimplementederror and notimplemented are not interchangeable, although they have similar names and purposes.

Ellipsis

And... Same.

Translation estimates some problems, see the original quote:

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

You can refer to the article: Python summary of the ellipsis object, the original (smaller):

In detail, for the 3rd, more experimentation is needed.

It seems that the interpretation of the official text is too simple, ah, there should be more official text introduction.

__debug__

If Python starts without using the-O (OH) option and its value is true, view the Assert statement official for more information.

Introduction to the-o option:

-o:optimize generated bytecode slightly; Also pythonoptimize=x

In addition, there are several constants that are imported by the site module during Python startup ( auto-import site can be disabled using the-S command-line option ), but these constants are added to the built-in namespaces for the interactive interpreter shell (the interactive Interpreter shell) is useful, but should not be used in the program, as follows:

Quit (Code=none)

Exit (Code=none)

The above two will often be used.

Copyright

Credits

License

Python Basics: Built-in constants

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.