Know current Python Version


There are multiple ways in which you can check which is your current Python version.

Example 1: Know the current Python Version Command Line/Terminal

% python -V

Note: If you are using Python 3.x you will get an error,

# python -V 

bash: python: command not found
% python -V

zsh: command not found: python

If you are using Python 3.x

% python3 -V
Python 3.10.8
% python3 --version
Knowing Python Version on Mac Example

--version flag was introduced in Python 2.5


Example 2: Know current Python Version Programmatically

At times you may not have access to the terminal, for example, a hosted Notebook, in such case you may make use of Python code to programmatically know the version.

You can make use of the sys package to know the current Python version,

import sys
print("Current Python version is: ",sys.version)
Output:

Current Python version is: 3.10.8 (main, Oct 21 2022, 22:22:30) [Clang 14.0.0 (clang-1400.0.29.202)]

Google Colab Knowing Python Version

Above is a screenshot of Google Colab Notebook, where the code was executed and the version obtained is 3.10.8.

-


Have Questions? Post them here!

Top Hashtags:

Advertisements

Advertisements




Advertisements