⚠️ 换成有变量参与,就折不动了

👁️ 2 人浏览 💬 0 人评论 ❤️ 添加收藏

换一段:y = x + 0。这次算式里有个变量。常量表变成什么?

def consts(src):
    """编译一段源码,把它的常量表取出来(None 不算)"""
    code = compile(src, "<s>", "exec")
    return tuple(x for x in code.co_consts if x is not None)

print("/".join(str(x) for x in consts('y = x + 0')))
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论