Python - ファイルを削除する

ファイルを削除するには os.remove または os.unlinke 関数を使用します。

ファイルの削除方法

os.remove または os.unlink 関数に削除したいファイルを指定します。 os.unlink 関数は os.remove の別名で、同じ動作をします。
import os

os.remove(path='削除するファイルのパス')
os.remove('削除するファイルのパス')

os.unlink(path='削除するファイルのパス')
os.unlinke('削除するファイルのパス')
サンプルコード
import os

# test.txt を作成
with open(file='./test.txt', mode='w') as f:
    f.write('test')

# test.txt を削除
os.remove(path='./test.txt')

検証環境