LoginSignup
4
3

More than 1 year has passed since last update.

[python3] コンソールをクリアする

Last updated at Posted at 2022-03-10

今回はPythonでコンソールをクリアする方法を説明します。

環境
・Python3.10 64bit
・Windows11

基本的な書き方

import os
os.system('cls')

[import os]の部分でosモジュールをインポートしています。
[os.system('cls')]の部分でコンソールをクリアしています。

注意
Linux、Macの場合は[os.system('cls')]を[os.system('clear')]に置き換えてください。

コード例

最後に、コード例を紹介します。

import os
import time

for i in range(10):
    print(i)
    time.sleep(1)
    os.system('cls')

上のコードは、コンソールのクリアを利用した1から10まで数えてくれるプログラムです。

(できればLGTMお願いします。)

4
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3