write() Function (write() Method) :-
write() Method का उपयोग किसी File में एक String लिखने के लिए किया जाता है। यह दिए गए String के Characters की संख्या Return करता है।
English: The write() method is used to write a string into a file. It returns the number of characters written.
Syntax:
यहाँ:
file – File Object है।
write() – Data लिखने का Method है।
string – वह Text है जिसे File में लिखना है।
Example 1: String लिखना
Example 2: write() का Return Value
Explanation:
Hello Python में कुल 12 Characters हैं। इसमें एक Space भी शामिल है। इसलिए write() Method 12 Return करता है।
Example 3: अलग-अलग बार write() का उपयोग
पहला write() File में Hello लिखता है।
दूसरा write() उसके तुरंत बाद Python लिखता है।
write() Automatically New Line नहीं जोड़ता।
Important Points:
write() एक String को File में Write करता है।
यह लिखे गए Characters की संख्या Return करता है।
write() Automatically New Line नहीं जोड़ता।
नई Line के लिए \n का उपयोग किया जाता है।
Text Mode में write() को String (str) देना आवश्यक है।