Python 3.10
message = {"action": "hello", "name": "Python"}
match message:
case {"action": "hello", "name": name}:
print(f"Hello, {name}")
case _:
print("Unknown action")message = {"action": "hello", "name": "Python"}
match message:
case {"action": "hello", "name": name}:
print(f"Hello, {name}")
case _:
print("Unknown action")def greet(name: str | None) -> str:
return f"Hello, {name or 'world'}"zip(..., strict=True) 在可迭代对象长度不一致时抛出 ValueError,避免静默截断。
怎么用配对字段和数据时,及早发现长度错误。
names = ["Ada", "Guido"]
scores = [98, 95]
print(dict(zip(names, scores, strict=True)))解释器能提供更具体的语法错误提示,包括未闭合括号和缺少冒号。
怎么用减少在报错位置与真正问题之间来回查找的时间。
没有找到匹配的中文解读。试试其他关键词,或查看下方官方目录。
自动同步官方目录,涵盖语言、标准库、弃用及迁移变化。标题保留官方原文;中文解读精选于上方。
官方目录中没有匹配项。