Skip to content

Instantly share code, notes, and snippets.

@AnimeshShaw
Created January 3, 2015 06:09
Show Gist options
  • Select an option

  • Save AnimeshShaw/4404bebef05bb323c86f to your computer and use it in GitHub Desktop.

Select an option

Save AnimeshShaw/4404bebef05bb323c86f to your computer and use it in GitHub Desktop.
Different ways to check Python version. More Details : http://www.rawcoders.com/Thread-Python-Different-ways-to-check-Python-version
'''
Created on 03-Jan-2015
@author: Psycho_Coder
'''
import platform
import sys
# Method 1
if platform.python_version()[0] == "3":
print( "My Python Interpreter version 3" )
elif platform.python_version()[0] == "2":
print( "My Python Interpreter version 2" )
# Method 2
if sys.winver[0] == "3":
print( "My Python Interpreter version 3" )
elif sys.winver[0] == "2":
print( "My Python Interpreter version 2" )
# Method 3
if sys.version[0] == "3":
print( "My Python Interpreter version 3" )
elif sys.version[0] == "2":
print( "My Python Interpreter version 2" )
# Method 4
if sys.version_info[0] == 3:
print( "My Python Interpreter version 3" )
elif sys.version_info[0] == 2:
print( "My Python Interpreter version 2" )
# Method 5
if sys.version_info > ( 3, 0 ):
print( "My Python Interpreter version 3" )
elif sys.version_info < ( 3, 0 ):
print( "My Python Interpreter version 2" )
# Method 6
if sys.hexversion > 0x03000000:
print( "My Python Interpreter version 3" )
elif sys.hexversion < 0x03000000:
print( "My Python Interpreter version 2" )
# Method 7
if platform.python_version_tuple()[0] == "3":
print( "My Python Interpreter version 3" )
elif platform.python_version_tuple()[0] == "2":
print( "My Python Interpreter version 2" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment