• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • VBA
  • About
You are here: Home / Python / Python Get Number of Cores Using os cpu_count() Function

Python Get Number of Cores Using os cpu_count() Function

February 9, 2022 Leave a Comment

The easiest way to get the number of cores in Python is to use the cpu_count() function from the Python os module.

import os

print(os.cpu_count())

#Output:
4

The Python os module gives us many useful functions for interacting with a computer’s operating system to gather information and make changes.

One piece of information which can be very useful is the number of processing cores or CPUs that a computer has.

We can easily get the number of cores using the os module cpu_count() function.

You can print the number of cores in your system using the following Python code.

import os

print(os.cpu_count())

#Output:
4

If Python cannot determine how many cores are in your system, then cpu_count() will return None.

Hopefully this article has been useful for you to learn how you can get the number of processing cores your computer and system has using Python.

Other Articles You'll Also Like:

  • 1.  How to Check if Variable is Defined in Python
  • 2.  How to Check if List is Empty in Python
  • 3.  Get Last Day of Month Using Python
  • 4.  Using Python to Remove Non-Empty Directory
  • 5.  Python Square Root Without Math Module – ** or Newton’s Method
  • 6.  Python math.factorial() function – Calculate Factorial of Number
  • 7.  How to Hide Turtle in Python with hideturtle() Function
  • 8.  Convert String into Tuple in Python
  • 9.  Draw Circle in Python Using turtle circle() Function
  • 10.  How to Rotate String in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2022 · The Programming Expert · About · Privacy Policy