Program Python untuk Ditambahkan ke File

0
(0)

Buka file dalam mode append dan tulis ke file itu

Isi file my_file.txt aku s

honda 1948
mercedes 1926
ford 1903

Keluaran

with open("my_file.txt", "a") as f:
   f.write("new text")

Isi file setelah ditambahkan adalah:

honda 1948
mercedes 1926
ford 1903new text

Buka file di append 'a' mode, dan tulis menggunakan write() metode.


Jika Anda ingin mempelajari lebih lanjut tentang berbagai jenis mode pembukaan file, lihat I / O file Python.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.