Learn practical skills, build real-world projects, and advance your career

Write File

file = open("myfile.txt", 'w')

file.write("Four people died after a fire broke out in a shopping mall in South Korea.\nThe fire started in a children´s play area inside the mall.\nNo children were inside the play area at the time.")

file.close()
  • r: (read)
  • w: (write)
  • a: (append)
  • wr: (read or write)

Read File

file = open("myfile.txt", 'r')
text = file.read() # Read entire file into a string
print(text)
Four people died after a fire broke out in a shopping mall in South Korea. The fire started in a children´s play area inside the mall. No children were inside the play area at the time.