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.

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap