Web Analytics

Python file.write() Method

File Method Write

The write() method writes a specified text to the file.

Where the specified text will be inserted depends on the file mode and stream position.

  • "a": The text will be inserted at the current file stream position, default at the end of the file.
  • "w": The file will be emptied before the text will be inserted at the current file stream position, default 0.

Syntax

file.write(text)

Parameters

Parameter Description
text Required. The text to be written.

Return Value

The number of bytes written.

Example

Using the write() method:

Output
Click Run to execute your code

Related Functions