How to Check Python Version in Ubuntu
Python is such a popular scripting language and various useful programs included in Ubuntu are written in Python. Therefore, Ubuntu Linux comes with Python preinstalled.
To check the Python version, Open the command line interface and execute the following command:
If you automate stuff with Python, sometimes you will need to check the Python version in a Python script. For this, we use the
sys module, which has the version and
version_info objects to check the Python version.
import sys print(sys.version.split())
version_info to print major version:
import sys print(sys.version_info.major)
Python 3 is the default version in Ubuntu 20.04 LTS, although Python 2 is still available to install.
One can install Python 2, by running the
apt install python2 command.