Python Practice › OS Module Programs › Program 42
Number of CPUs
Write a Python program to get the number of CPUs with os.cpu_count().
Output
int True
Approach
- It returns an int, or None if unknown.
Solution
import os n = os.cpu_count()print(type(n).__name__, n is not None and n >= 1)Output
int True
Note
The real number depends on your machine, which is why the example prints a check.
Learn the concept
New to this topic? Read the lesson, then come back.