问题描述
清空命令行很简单,用cls
命令即可。但在命令行交互界面写了很多 Python 代码,看着很不舒服,如何清空后从头开始写?
解决方案
os.system(command)
使得在子 shell 中执行单个字符串命令成为可能。
>>> import os
>>> _ = os.system('cls')
演示截图

温馨提示
退出 Python 命令行交互界面只需输入exit()
指令即可。

引用参考
https://docs.python.org/3/library/os.html#os.system