writelines() Function (writelines() Method) :-
writelines() Method का उपयोग किसी Iterable जैसे List या Tuple में मौजूद कई Strings को एक साथ File में Write करने के लिए किया जाता है।
English: The writelines() method is used to write multiple strings from an iterable, such as a list or tuple, into a file.
Syntax:
यहाँ iterable में एक से अधिक Strings हो सकती हैं।
Example 1: List की सहायता से Multiple Lines लिखना
Explanation:
data एक List है।
List में चार Strings मौजूद हैं।
writelines() सभी Strings को File में Write करता है।
प्रत्येक String में \n होने के कारण अलग-अलग Lines बनती हैं।
Example 2: Tuple की सहायता से Data लिखना
Explanation: writelines() Tuple में मौजूद सभी Strings को File में Write करता है।
Example 3: writelines() में Newline न देना
Explanation:
writelines() Automatically Newline (\n) नहीं जोड़ता। इसलिए सभी Strings एक-दूसरे के तुरंत बाद लिखी जाती हैं।
Example 4: writelines() का Return Value
Explanation:writelines() Method कोई Value Return नहीं करता। इसका Return Value None होता है। Important Points:
writelines() एक साथ कई Strings Write करता है।
इसमें List, Tuple या अन्य Iterable दिया जा सकता है।
writelines() Automatically Newline नहीं जोड़ता।
अलग-अलग Lines के लिए Strings में \n देना आवश्यक है।
इसका Return Value None होता है।
Iterable के Elements Text Mode में Strings होने चाहिए।