共計 293 個字符,預計需要花費 1 分鐘才能閱讀完成。
在 Python 中,要清空 shell 界面可以使用以下兩種方法。
- 使用
os.system
函數調用系統命令清空 shell 界面。
import os
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
clear()
- 使用
print
函數打印特殊的控制字符\033c
清空 shell 界面。
def clear():
print('\033c', end='')
clear()
這兩種方法都可以在 Windows 和 Unix 系統上使用。
丸趣 TV 網 – 提供最優質的資源集合!
正文完