Skip to content
Related Articles

Related Articles

Improve Article

Python | os.cpu_count() method

  • Last Updated : 25 Jun, 2019

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.cpu_count() method in Python is used to get the number of CPUs in the system. This method returns None if number of CPUs in the system is undetermined.

Syntax: os.cpu_count()

Parameter: No parameter is required.

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



Code: Use of os.cpu_count() method to get the number of CPUs in the system




# Python program to explain os.cpu_count() method  
  
# importing os module 
import os
  
  
# Get the number of CPUs
# in the system using
# os.cpu_count() method
cpuCount = os.cpu_count()
  
# Print the number of
# CPUs in the system
print("Number of CPUs in the system:", cpuCount)
Output:
Number of CPUs in the system: 4

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :