Menu
CoddyTech

Absence Is Not a Null Pointer

Lesson 7 of 48 in Coddy's Python for C Developers course.

C NULL is a null pointer constant used in pointer contexts; it is not an ordinary missing integer value. Python None is a singleton object representing absence and can be bound to any name. Use is None to test it. True and False are Python boolean objects and print with capitals. None, zero, and False are distinct meanings even though all test false in conditions. The task uses None only when no positive seat count is being reported; it still prints a separate boolean result.

C: complete example.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
int main(void) {
    int *p = NULL;
    printf("%d %d\n", p == NULL, 4 > 2);
    return 0;
}

Python: complete example.py

p = None
print(p is None, 4 > 2)

Watch the difference

A Python None value is not a raw address you can dereference or free. Comparing it numerically with an integer using > raises TypeError. Test absence before arithmetic.

Your code goes in main.py. The locked driver.py is the entry file, supplies execution and checks, and cannot be edited.

challenge icon

Challenge

Beginner

For a seat count from 0 through 20, print the boolean result of checking for available seats. Next print the positive count, or None when it is zero. Begin the reported value at None and replace it only for positive counts.

Keep the supplied input scaffold. Output only the requested results, with a newline after each line and no prompts.

C comparisons formatted as integers produce 0 or 1; this task requires Python True or False.

Your code goes in main.py. The locked driver.py is the entry file, supplies execution and checks, and cannot be edited.

Try it yourself

# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module

run_module("main", run_name="__main__")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Python for C Developers

Practice on your own: Online Python compiler