...

/

File Opening Modes

File Opening Modes

Learn about different file opening modes in Python.

We'll cover the following...

File opening modes

There are multiple file-opening modes available, as shown in the table below.

'r'

Opens a file for reading in text mode.

'w'

Opens a file for writing in text mode.

'a'

Opens a file for appending in text mode.

'r+'

Opens a file for reading and writing in text mode.

'w+'

Opens a file for writing and reading in text mode.

'a+'

Opens a file for appending and reading in text mode.

'rb'

Opens a file for reading in binary mode.

'wb'

Opens a file for writing in binary mode.

'ab'

Opens a file for appending in binary mode.

'rb+'

Opens a file for reading and writing in binary mode.

'wb+'

Opens a file for writing and reading in binary mode.

'ab+'

Opens file for appending and reading in binary mode.

Note: If the mode argument is not mentioned when ...