← Python from Scratch Lesson 77 of 78 · 5 XP

Warm-up: does the file exist? warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

The os module has os.path.exists(path) — it returns True if the file exists and False if it doesn't:

import os
print(os.path.exists("notes.txt"))

Task. Write a function exists(path) that returns True if the file exists and False if it doesn't.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.