如何在命令行中运行多个语句?

时间:2019-04-16 20:35:15

标签: python windows command-line

是否可以从Windows的命令行在Python中运行多个命令?

这是我在Windows中的命令行上尝试过的。

python -c print(4)\nprint(5)

我收到的错误如下:

SyntaxError: unexpected character after line continuation character

我上面写的东西甚至可以做吗?

我可以运行以下多个语句吗?

python -c a=5\nb=3\nprint(a+b)

如果可以,怎么办?

1 个答案:

答案 0 :(得分:0)

分号,而不是换行符

python -c "print(4); print(5)"
# prints 4, and then 5
python -c "a=5; b=3; print(a+b)"
# prints 8
相关问题