4Geeks logo
4Geeks logo
About us

Learning library

For all the self-taught geeks out there, here our content library with most of the learning materials we have produces throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Full-Stack Software Developer

Data Science and Machine Learning - 16 wks

Search from all Lessons

Social & live learning

The most efficient way to learn: Join a cohort with classmates just like you, live streams, impromptu coding sessions, live tutorials with real experts, and stay motivated.

← Back to How to's

Continue learning for free about:

Edit on Github

How to check python version?

Written by:

1python --version 2#Output: Python 3.11.0

Checking the python version

If you have installed python on your system, checking the python version it is as simple as writing the following code, doesn't matter the Operating System (OS) you are using since python will respond to the same commands on all of them.

For Windows users:

  • Open command terminal (search on the menu bar for cmd or press WIN + R to open the run window and type cmd)
  • Type python -V or python --version

For Linux users:

  • Open a new terminal
  • Type python -V or python --version

For MacOS users:

  • Go to Finder
  • Click on Applications
  • Select Utilities
  • Terminal
  • Type python -V or python --version
1python -V 2#Output: Python 3.11.0

Checking the Python Script Version

If you need to check the Python version that you are using for a project (remember we can have different python versions installed at the same time on our System, we call it Python Script Version), you can do it like this:

Using sys module

1import sys 2print (sys.version) 3#Output: 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]

Using the platform module

1import platform 2print(platform.python_version()) 3#Output: 3.10.4

Both options will return the version with a string format. We can obtain this information in the tuple format as well. The return tuple syntax will contain five components: major, minor, micro, release level, and serial:

1import sys 2print (sys.version_info) 3# Output: sys.version_info(major=3, minor=10, micro=4, releaselevel='final', serial=0)

Since we are receiving the information in a Tuple format we can access and extract information using an index or by referring to it's name.

1import sys 2print(sys.version_info[0]) 3#Output: 3 4print(sys.version_info.releaselevel) 5#Output: final

Hope you enjoy the reading and keep on the Geek side!