← Python from Scratch
Lesson 19 of 78 · 10 XP
None — "nothing"
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
None means the absence of a value. It isn't zero or an empty string — it's literally "nothing here".
Where you'll meet it:
result = None # the value isn't known yet
def say_hi():
print("Hello")
x = say_hi() # a function without return returns None
print(x) # None
The right way to check for None is with is, not ==:
if result is None:
print("No result yet")
None is handy to return when "there's no answer": for example, a function looked for an element and didn't find it.
Task. Write a function first_even(nums) that returns the first even number in the list, or None if there are no even numbers. Use a for loop (we'll cover it in detail later):
for n in nums:
... # this block runs for each n in the list
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.