Computer Science, asked by pavankalyankakani9, 1 year ago

Opening a file in append mode in Python

Answers

Answered by sahilx17
0
To open files in append mode, specify 'a' as the mode(a=append). For example,

f = open('my_file.txt', 'a')
file_content = f.read()
f.write('Hello World')
f.close()

Above code opens my_file.txt in append mode and appends the file to contain "Hello World" at the end.
Answered by smartbrainz
0

Explanation:

  • In Python, Opening a file in 'append', by specifying 'a' as the file open mode (a=append). This allows appending a new text to the already existing file or the new file.
  • The opening of a file in 'a+' as the mode will build a new file if it does not exist. This function acts similar to the 'write() function', but instead of overwriting the file, the 'append() function' adds material to the original file.

Similar questions