Skip to content

无

一句话解释

无 是 Python's 空 值 — singleton representing absence 的 值.

用大白话说

None 是 Python's representation 的 "否值" or "无." 它是 singleton — 那里是仅 one None 对象 in 所有的 Python. Use is None or is not None 到测试 for 它, 不 == None.

无 is returned by functions that don't have a return statement, and by methods like 列表.append() that modify in place. It is commonly used as a default argument value to distinguish "不 provided" from "provided as falsy."

无 is falsy in boolean contexts. It has no type methods. Its type is NoneType. It cannot be used in arithmetic or compared with < or >.

示例

python
x = None

print(x is None)      # True
print(type(x))       # <class 'NoneType'>

# Functions without return return None
def greet(name):
    print(f"Hi, {name}")

result = greet("Alice")  # Prints: Hi, Alice
print(result)            # None

# None as default argument
def func(items=None):
    if items is None:
        items = []
    return items

无 represents absence 的 值. 测试 使用 '是 无'. 函数 不使用 返回 give 无.

常见混淆

  • 容易混淆的对象: 假

    关键区别: 无 平均值 '否 值 at 所有'. 假 是 布尔值 值 meaning '不 真'. 无 是 NoneType; 假 是 bool. 两者都 是 falsy, 但 它们 是 不同 对象: 无 == 假 是 假.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表