FAQ: Learn Python: Files - Writing a File

This community-built FAQ covers the “Writing a File” exercise from the lesson “Learn Python: Files”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Python 3

FAQs on the exercise Writing a File

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

A post was split to a new topic: I found this frustrating

3 posts were split to a new topic: Is there a way to open a file in both read and write?

Write, Read, Tell and Seek

with open("bad_bands.txt", 'r+') as bad_bands_doc:
  bad_bands_doc.write("Captain Beefheart")
  myRead = bad_bands_doc.read()

with open('bad_bands.txt', 'w') as bad_bands_doc:
  bad_bands = bad_bands_doc.write("FT Islands")


This outputs 10 somehow.
I was expecting to see FT Islands.
Why is this returning 10(seems like that is the length of the string FT Islands)?