Written by:
1python --version 2#Output: Python 3.11.0
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.
cmd
or press WIN + R
to open the run window and type cmd
)python -V
or python --version
python -V
or python --version
python -V
or python --version
1python -V 2#Output: Python 3.11.0
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:
sys
module1import 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)]
platform
module1import 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!