Python constants like None (according to the reference)

Introduction

I searched for ** constants ** in python. It doesn't look right, though.

python constant

python, constant If you go around, you will reach the following section of the reference. https://docs.python.org/ja/3/library/constants.html

Quoted below.

Built-in ** constant ** There are several ** constants ** in the built-in namespace. List of ** constants **:

Just in case, https://docs.python.org/3/library/constants.html Also quote

Built-in Constants A small number of constants live in the built-in namespace. They are:

Here, the following six are shown.

False True None NotImplemented Ellipsis __debug__

Look at the value

>>> False
False
>>>
>>> True
True
>>>
>>> None
>>>
>>> NotImplemented
NotImplemented
>>>
>>> Ellipsis
Ellipsis
>>>
>>> __debug__
True
>>>

Try substituting a value

>>>
>>> False = 3
  File "<stdin>", line 1
SyntaxError: can't assign to keyword
>>>
>>> True = 3
  File "<stdin>", line 1
SyntaxError: can't assign to keyword
>>>
>>> None = 3
  File "<stdin>", line 1
SyntaxError: can't assign to keyword
>>>
>>> NotImplemented = 3
>>>
>>> Ellipsis = 3
>>>
>>> __debug__ = 3
  File "<stdin>", line 1
SyntaxError: assignment to keyword
>>>
>>>

⇒ ** ↓ ↓ ↓ Not Implemented and Ellipsis can be assigned values. (Although it is a constant ...) ** It's a constant with a slightly different meaning.

>>> NotImplemented
3
>>>
>>> Ellipsis
3
>>>
>>> type(NotImplemented)
<class 'int'>
>>> type(Ellipsis)
<class 'int'>
>>>

↑↑↑ It was seriously substituted. .. .. It's an int. .. ..

Supplement

I received a comment, so I added it. False True None Is a ** keyword **, he said.

below https://docs.python.org/ja/3/reference/lexical_analysis.html#identifiers To quote

2.3.1. Keyword¶ The following identifiers are used as reserved words or keywords in the Python language and cannot be used as regular identifiers. Keywords must be spelled exactly as follows:

False await else import pass None break except in raise True class finally is return and continue for lambda try as def from nonlocal while assert del global not with async elif if or yield

Also, Shown in the comments http://python-history.blogspot.com/2013/11/story-of-none-true-false.html https://www.python.org/dev/peps/pep-0285/ Will also be helpful.

Summary

It didn't feel right. If you have any comments, please. : candy:

If anything, it's an article that feels like ** "There is something that made me feel sorry for the reference" **. .. ..

Recommended Posts

Python constants like None (according to the reference)
Dot according to the image
Leave the troublesome processing to Python
In the python command python points to python3.8
How to get the Python version
[Python] How to import the library
[Python] Change the alphabet to numbers
The 15th offline real-time how to write reference problem in Python
The 14th offline real-time how to write reference problem in python
Python script for KiCad-Pre-place footprint almost according to the schematic layout
The 18th offline real-time how to write reference problem in Python
The 17th offline real-time how to write reference problem implemented in Python
The 16th offline real-time how to write reference problem to solve with Python
To reference environment variables in Python in Blender
Python amateurs try to summarize the list ①
The 19th offline real-time how to write reference problem to solve with Python
An example of the answer to the reference question of the study session. In python.
The road to compiling to Python 3 with Thrift
How to use the C library in Python
Dynamically generate sqlalchemy filter according to the conditions
Introduction to Python Let's prepare the development environment
Try to solve the Python class inheritance problem
[Python] How to change the date format (display format)
Just add the python array to the json data
The easiest way to synthesize speech with python
[Introduction to Udemy Python 3 + Application] 38. When judging None
Try to solve the man-machine chart with Python
Specify the Python executable to use with virtualenv
To dynamically replace the next method in python
Say hello to the world with Python with IntelliJ
Draw graphs in Julia ... Leave the graphs to Python
Excel X Python The fastest way to work
The easiest way to use OpenCV with python
The trick to write flatten concisely in python
[Introduction to Python3 Day 20] Chapter 9 Unraveling the Web (9.1-9.4)
[Algorithm x Python] How to use the list
Use the Python framework "cocotb" to test Verilog.
How to erase the characters output by Python
Introduction to Python with Atom (on the way)
How to get the files in the [Python] folder
[Introduction to Algorithm] Find the shortest path [Python3]
A python amateur tries to summarize the list ②
[Python] I will upload the FTP to the FTP server.
json.dumping None in python returns the string null
Knowledge notes needed to understand the Python framework
[Python] Throw a message to the slack channel
An article summarizing the pitfalls addicted to python
I want to display the progress in Python!
Change the string to be replaced according to the matched string by replacing with Python regular expression
Try to create a waveform (audio spectrum) that moves according to the sound with python
About python reference
Python reference page
"Backport" to python 2
Easy way to check the source of Python modules
python beginners tried to predict the number of criminals
[Python] How to remove duplicate values from the list
How to retrieve the nth largest value in Python
Python practice Convert the input year to the Japanese calendar
I tried to graph the packages installed in Python
The wall of changing the Django service from Python 2.7 to Python 3
How to get the variable name itself in python