how to delete the content of a file in python code example Example: python delete all data from file file = open("sample.txt","r+") file.truncate(0) file.close()