代码执行与调试
内置函数
breakpoint函数
函数签名:breakpoint(*args, **kws)
参数说明:
args:要传递给断点的参数kws:要传递给断点的关键字参数
返回值:
- 无返回值
compile函数
compile() 函数将 Python 源代码编译为代码对象,可被 eval() 或 exec() 执行。预编译可提高重复执行效率。
函数签名:compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1) -> code object
参数说明:
-
source(必需): -
要编译的 Python 源代码
-
可以是字符串、字节串或 AST 对象
-
示例:
"x = 1 + 2"、"print('hello')" -
filename(必需): -
字符串,指定代码来源文件名(用于错误提示)
-
约定:
'<string>'(字符串)、'<stdin>'(标准输入)、'script.py'(实际文件) -
mode(必需): 编译模式,决定代码类型和执行方式: -
'eval'