- The os.truncate() function removes the contents of a file that is available beyond the specified length. The remaining contents are left untouched.
# Example Python program that truncates a file
# Truncate the file to have only the first two lines
# Open the truncated file
# Read the file contents and print
|b'Rain, rain, go away\nCome again some other day'|