Lesson 30 of 34

Files: लिहिणे आणि वाचणे

9 min 30 XP

प्रोग्राम संपल्यावरही data ठेवायचा असेल तर तो file मध्ये save करा. open(name, "w") लिहिते, "a" जोडते आणि "r" वाचते. with वापरल्यास file आपोआप बंद होते.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

File ओळीनुसार वाचण्यासाठी तिच्यावर loop चालवा. strip() प्रत्येक ओळीच्या शेवटचा \n काढते.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

इथे files फक्त तुमच्या browser मध्ये राहतात आणि refresh केल्यावर नाहीशा होतात. संगणकावर Python install केल्यास खऱ्या files तयार होतात.

Challenge

+30 XP

names = ["arun", "priya", "kavi"]. प्रत्येक नाव "students.txt" मध्ये स्वतंत्र ओळीत लिहा. मग file पुन्हा वाचून प्रत्येक नाव capitals मध्ये (upper) print करा.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.