Starlit Daily

📚 › Python: the friendliest first language

12. Reading and writing files

इस लेख का अनुवाद अपने आप होगा। अभी अंग्रेज़ी में दिखाया जा रहा है।

open() opens a file. Use with open(...) as f so the file closes automatically. f.write() writes text, and f.read() reads the whole file.

Use "w" to write (replacing the file), "a" to add to the end, and "r" to read.

उदाहरण देखें

with open("notes.txt", "w") as f:
    f.write("Hello file")

✍️ अब आपकी बारी

Make a list words holding Hi and Python, then print them joined with one space.

← कोर्स पर वापस