python中什么是None,True,False?

2024-04-19 18:36:29 发布

您现在位置:Python中文网/ 问答频道 /正文

它们是关键字、常量还是函数?如果它们是常量,它们的类型是什么?python似乎没有boolean类型。在


Tags: 函数类型关键字常量boolean
1条回答
网友
1楼 · 发布于 2024-04-19 18:36:29

Python Documentation拥有一切,你只需要知道在哪里找:

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

False

The false value of the bool type. Assignments to False are illegal and raise a SyntaxError.

True

The true value of the bool type. Assignments to True are illegal and raise a SyntaxError.

None

The sole value of the type NoneType. None is frequently used to represent the absence of a value, as when default arguments are not passed to a function. Assignments to None are illegal and raise a SyntaxError.

还有

None

This type has a single value. There is a single object with this value. This object is accessed through the built-in name None. It is used to signify the absence of a value in many situations, e.g., it is returned from functions that don’t explicitly return anything. Its truth value is false.

以及

Booleans (bool)

These represent the truth values False and True. The two objects representing the values False and True are the only Boolean objects. The Boolean type is a subtype of the integer type, and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively.

进一步阅读

相关问题 更多 >