Open In App

Python | os.cpu_count() method

Last Updated : 23 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

]os.cpu_count() method in Python is used to get the number of CPUs in the system. This method returns None if the number of CPUs in the system is undetermined. In this article, we will see how to get several cores in Python.

Python os.cpu_count() Method Syntax

Syntax: os.cpu_count()

Parameter: No parameter is required.

Return Type: This method returns an integer value that denotes the number of CPUs in the system. None is returned if the number of CPUs is undetermined.

os.cpu_count() Method in Python Examples

Below are some examples of the os.cpu_count() function of the OS module in Python:

Python Get Number of Cores CPU Using os.cpu_count()

We can use of os.cpu_count() method to get the number of CPUs in the system. In this example, the script determines and prints the number of CPUs available in the system using Python’s `os.cpu_count()` function.

Python3




import os
 
cpuCount = os.cpu_count()
print("Number of CPUs in the system:", cpuCount)


Output

Number of CPUs in the system: 4


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads