Python

Python Menu

Python

Python File write() - Definition, Syntax, Parameters, Examples

Definition

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(byte)

Parameters

Parameter Description
byte The text or byte object that will be inserted.

Examples:

f = open("myFile.txt", "a")
f.write("Write me!")
f.close()

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods