How to Use open() Function in PythonPython Basics


The open() function opens the file and returns a corresponding file object.

Example

# opens test.text file of the current directory
f = open("test.txt")

# full path
f = open("C:/Python3/test.txt")

Syntax

open(name[, mode[, buffering]])

Parameters

The parameters include the required filename and optional open mode.

Return Value

The method doesn’t return any value.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us