I searched for ** constants ** in python. It doesn't look right, though.
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. .. ..
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.
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