What does Python’s with open(‘file.txt’, ‘r’) as f: ensure?

Python Developer Medium

Python Developer — Medium

What does Python’s with open(‘file.txt’, ‘r’) as f: ensure?

Key points

  • The 'with' statement in Python is used for resource management.
  • The 'r' mode in open() function stands for read-only.
  • Closing the file explicitly is not required when using 'with open()'.

Ready to go further?

Related questions