Key Concepts

Review core concepts you need to learn to master this subject

Python Readline Method

To read only one line instead of multiple lines in a Python file, use the method .readline() on a file object that is returned from the open() function. Every subsequent .readline() will extract the next line in the file if it exists.

with open('story.txt') as story_object: print(story_object.readline())

will print only the first line in story.txt.

Learn Python: Files
Lesson 1 of 1

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo