Check Python Verison for Different Processing in a Python Script

By | June 16, 2021

There are python 2.x and python 3.x. There are some different between them. Sometimes, we have to implement different processing for them. In this tutorial, we will introduce you how to do.

Check Python Verison for Different Processing in a Python Script

Here is the tutorial:

import six

if six.PY2:
    print("this is python 2")
if six.PY3:
    print("this is python 3")

In this code, we will use six package to check python version.

If you are running it on python 2.x, it will output: this is python 2, otherwise, it will output: this is python 3

Then we can implement different processing based on it.

Leave a Reply