Python – Find File object – open() Function with Examples

open() function is used to find the opens the file (if possible) and returns a corresponding file object in Python for the given input.

open() function is a part of Python Built-in Functions.

Syntax of open() Function

The syntax of open() function in Python is:

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

 

Parameters of open() Function in Python

x – Where x is any valid . This parameter is required.

 

Compatibility

open() function is available and compatible with both Python 2.x and 3.x.

 

Return Value of open() Function in Python

open() function returns opens the file (if possible) and returns a corresponding file object for the given input.

 

Python open() Function Example 1

Example CODE

Output:

 

Python open() Function Example 2

Example CODE

Output: