Function Details: write

Description


Write string s to the stream and return the number of characters written.


Extended Description


The write() method writes the specified string to the file stream. It returns the number of characters written. In text mode, the string is encoded before writing. The file must be opened in a write mode ('w', 'a', or 'r+').


Function Signature



Module: io

Class: TextIOWrapper

Parameters



Parameter List


  • s: str

Return


Returns an integer representing the number of characters written.


Return Type


int

Output

Explanation

This example demonstrates the basic usage of write(). It writes a string to the file and prints the number of characters written.