我可以从终端执行 python 语句吗?

Naf*_*Kay 2 debian python

我想简单地执行 Python 命令,而不必编写脚本或输入解释器。有没有办法让我可以运行类似的东西:

python --execute "pow(12.31351,2)"
Run Code Online (Sandbox Code Playgroud)

并简单地打印结果?

小智 7

您可以使用-c参数,例如python -c "print 123",请参阅python --help

usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
     -c cmd : program passed in as string (terminates option list)
Run Code Online (Sandbox Code Playgroud)