top of page
Image by Alexander Grey

Write to a File with Python

Unit 2 Summary - part 2

Image by Nareeta Martin

How to create a TXT file with Python

Image by Annie Spratt
Image by Kenrick Mills
Writing to a file coding:
Read Write File p. 69a.png
  • Line 2 and 8: message is a variable to add a text.​

​​

  • Line 4's (filename, "w") is used to OVERWRITE a file.

​​

  • Line 5, 6, 7: /n is used to create a new line​

Image by Scott Webb
Read Write File p. 69b.png
  • Line 2 & 5: header is a variable to add a text.

​​

  • Line 4's (filename, "a") is used if you don't want to overwrite, you just want to add something to the end of the file.​​​

Image by Krystal Ng
Read Write File p. 70 .png
  • Line 2 & 3 are used to let users input their own item to the text.

Image by Adrian Infernus
Read Write File p. 71b.png
  • Line 2 is used to add a list in the file.

​​

  • Line 5 is to add the list with for loop.

Image by J Lee

How to read a TXT file with Python

Image by Pawel Czerwinski
Image by Maxim Berg
Image by Maxim Berg
Read a TXT file coding:
Read Write File p. 71a.png
  • Line 3 is used to open a file on Python

​​

  • Line 5 is used to display the list with for loop.

Image by Tamanna Rumee
Visconsio Nekoland Logo.jpg
PT. Visconsio Kaya Jaya Masyhur

© 2020-2023 by Miana Kitty

bottom of page