Opening and Closing Files

open() and close() functions

Interview Relevant: Basic file I/O

Opening Files

Use the built-in open() function.

Code Examples

python
1f = open("file.txt", "r")
2content = f.read()
3f.close()  # Don't forget this!

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In