首页 > 试题广场 >

以下代码在CPython 3.11+运行时执行,输出是什么?

[单选题]
以下代码在CPython 3.11+运行时执行,输出是什么?
from typing import reveal_type
x: int | str = 42
reveal_type(x)
  • 运行时无输出
  • 运行时打印Runtime type is 'int | str'
  • 运行时打印type of x is int | str(Python 3.11+的reveal_type为内置函数,显示静态注解类型)
  • 运行时抛出ImportError,因为reveal_type不可从typing导入
  • 运行时打印Runtime type is 'int'(Python 3.11+内置reveal_type显示运行时类型)

这道题你会答吗?花几分钟告诉大家答案吧!