Python - 065 : Perform write on a file in python

Publié le: 23 juillet 2023
sur la chaîne: The Digital Folks
96
2

The write() method:
This function inserts the string into the text file on a single line.

Based on the file we have created above, the below line of code will insert the string into the created text file, which is "myfile.txt.”


file.write("Hello There\n")
The writelines() method:
This function inserts multiple strings at the same time. A list of string elements is created, and each string is then added to the text file.

Using the previously created file above, the below line of code will insert the string into the created text file, which is "myfile.txt.”

f.writelines(["Hello World ", "You are welcome to Fcc\n"])


Sur cette page du site, vous pouvez voir la vidéo en ligne Python - 065 : Perform write on a file in python durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur The Digital Folks 23 juillet 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 96 fois et il a aimé 2 téléspectateurs. Bon visionnage!