Skip to content

Input & Output¶

About This Lesson¶

Master reading from and writing to files in Python. Learn file handling, different file modes, and best practices for working with file I/O.

What You'll Learn¶

  • Reading files (read, readline, readlines)
  • Writing files (write, writelines)
  • File modes (r, w, a, r+, etc.)
  • The with statement and context managers
  • Working with file paths
  • Binary vs text files
  • Common file operations
  • Use the MkDocs navigation on the left to move between lessons
  • The notebook below is fully interactive - you can run and edit code
  • Your changes are saved in your browser's local storage

Interactive Notebook¶


Having trouble with the embedded notebook? Try one of these: