Created
January 3, 2015 06:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| 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