💡 What You'll Learn
Files let you save data permanently. Use open() to create or read files. Remember to close files when done, or use with to auto-close them.
💾 In the browser, we simulate file operations. In real Python, files are saved to your computer!
files.py
1with open("notes.txt", "w") as f:
2 f.write("Hello from file!")
3with open("notes.txt", "r") as f:
4 content = f.read()
📺 Simulated File Operations
File content will appear here
🎯 Your Challenges
1Append Mode
Add more text without deleting existing content
2Read Lines
Use readlines() to get each line separately
3Line Count
Count how many lines are in the file
📚 What You Learned
open("file.txt", "w")opens for writingopen("file.txt", "r")opens for readingopen("file.txt", "a")opens for appendingwithensures files close automatically