📚 › 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.